First off, it's worth pointing out that PHP is not "messing up" anything. It's escaping characters, which may look weird, but it is perfectly valid and when you json_decode it later it will be just the same as it was originally. See here: https://3v4l.org/Smj2F

If you don't like the escaping though, you can use the JSON_UNESCAPED_UNICODE flag:

https://www.php.net/function.json-encode

This flag will "encode multibyte Unicode characters literally" according to https://www.php.net/manual/en/json.constants.php.

So you can do:

json_encode($array, JSON_UNESCAPED_UNICODE);

And it will give you the following output:

["M-am întîlnit ieri cu","fosta mea profă de matematică"]

Working example: https://3v4l.org/daETG

Answer from jszobody on Stack Overflow
🌐
W3Schools
w3schools.com › js › js_json_php.asp
JSON PHP
Before you send the request to the server, convert the JSON object into a string and send it as a parameter to the url of the PHP page: Use JSON.stringify() to convert the JavaScript object into JSON:
Discussions

FR: change JSON::toString output to match php & javascript json_encode - Feature Requests - JUCE
Php’s json_encode produces json-formatted text that does not have a space after the ":". JUCE’s JSON::toString does. It happens here in void DynamicObject::writeAsJSON (OutputStream& out, const int indentLevel, const bool allOnOneLine, int maximumDecimalPlaces): out More on forum.juce.com
🌐 forum.juce.com
1
December 9, 2022
php - how to use JSON.stringify and json_decode() properly - Stack Overflow
Im trying to pass a mulitidimensional Javascript array to another page on my site by: using JSON.stringify on the array assigning the resultant value to an input field posting that field to the sec... More on stackoverflow.com
🌐 stackoverflow.com
Error using json.stringify to send array to php
🌐 forum.jquery.com
[PHP / JavaScript] How can I avoid removing square brackets from arrays in PHP when using json_encode
So I have an array of objects that I converted to JSON using JSON.stringify in JavaScript You turn the array into a string representation of JSON data, there's no reason to call json_encode on that string, json_encode is for calling on php arrays and objects. More on reddit.com
🌐 r/learnprogramming
4
1
January 31, 2014
🌐
PHP
php.net › manual › en › function.json-encode.php
PHP: json_encode - Manual
If a value to be serialized is an object, then by default only publicly visible properties will be included. Alternatively, a class may implement JsonSerializable to control how its values are serialized to JSON.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › JSON › stringify
JSON.stringify() - JavaScript | MDN
The value to convert to a JSON string. ... A function that alters the behavior of the stringification process, or an array of strings and numbers that specifies properties of value to be included in the output. If replacer is an array, all elements in this array that are not strings or numbers (either primitives or wrapper objects), including Symbol values, are completely ignored.
🌐
W3Schools
w3schools.com › js › js_json_stringify.asp
JSON.stringify()
You can convert any JavaScript datatype into a string with JSON.stringify().
🌐
JUCE
forum.juce.com › feature requests
FR: change JSON::toString output to match php & javascript json_encode - Feature Requests - JUCE
December 9, 2022 - Php’s json_encode produces json-formatted text that does not have a space after the ":". JUCE’s JSON::toString does. It happens here in void DynamicObject::writeAsJSON (OutputStream& out, const int indentLevel, const b…
Find elsewhere
🌐
Json Parser Online
json.parser.online.fr
Json Parser Online
Analyze your JSON string as you type with an online Javascript parser, featuring tree view and syntax highlighting. Processing is done locally: no data send to server.
🌐
Jsontostring
jsontostring.com
Convert JSON to String Online
JSON - JavaScript Object Notation. JSON - for storing and exchanging data. Make use of our Json to String Online Converter tool which brings the desired solution in minutes. If you have a huge set of content to be converted into a string, our tool can make your work easier!
🌐
Jsontophp
jsontophp.com
Convert JSON Object to PHP Array Online
JSON to PHP array converter online - Convert the given JSON object or Array into beautified PHP array that can be used instantly into your PHP file as a PHP array
🌐
JSON Formatter
jsonformatter.curiousconcept.com
JSON Formatter & Validator
The JSON Formatter & Validator beautifies and debugs JSON data with advanced formatting and validation algorithms.
🌐
Symfony
symfony.com › home › documentation › how to use the serializer
How to Use the Serializer (Symfony Docs)
Symfony provides a serializer to transform data structures from one format to PHP objects and the other way around. This is most commonly used when building an API or communicating with third party APIs. The serializer can transform an incoming JSON request payload to a PHP object that is consumed by your application.
🌐
JSONLint
jsonlint.com
JSONLint - The JSON Validator
JSON Stringify · JSON Diff · JSON Schema Validator · JSON Path Query · Mastering JSON Format: Advantages, Best Practices and Comparison with Other Data Formats · Common JSON Mistakes and How to Avoid Them · Mastering JSON in JavaScript: Comprehensive Examples and Techniques ·
🌐
JSON Formatter
jsonformatter.org › json-stringify-online
JSON Stringify Online using JSON.Stringify()
JSON Stringify Online helps convert string value to JSON String using JSON.Stringify().
🌐
Laravel
laravel.com › docs › 12.x › eloquent-serialization
Eloquent: Serialization | Laravel 12.x - The clean stack for Artisans and agents
To convert a model to JSON, you should use the toJson method. Like toArray, the toJson method is recursive, so all attributes and relations will be converted to JSON. You may also specify any JSON encoding options that are supported by PHP: