D
D
DmitryLife2022-03-11 00:42:33
PHP
DmitryLife, 2022-03-11 00:42:33

How to remove escaping from JSON?

Good afternoon. I am translating for a chat bot.
I save all texts in json format.

file_put_contents('data/rus.json',json_encode($rus,JSON_UNESCAPED_UNICODE));


Faced the problem of escaping line breaks - \n. I get the result something like this:
{"text":"*Welcome to the Bot.* \\n\\n__Bot__ will help you to be among those who will receive benefits as a Forsage member.\\nAnd also provide the necessary information in time."} (* piece of JSON)

Now, when I output in the bot, \\n is converted to \n

As an option, I decided to use: But the following result is returned: \ \n\ \n__Bot__ will help you get among those It's not entirely clear how to solve this problem. I see another solution, save each line separately, and concatenate at the output stage. But it seems like a difficult decision. Thank you for your attention.
$json= str_replace('\\n', ' \n', $json);



Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2022-03-11
@DmitryLife

this problem has nothing to do with json_encode.
somewhere extra shielding is added.
you need to find that shit code that adds it, and remove
it and at the same time learn how to check your code before writing a question to the toaster

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question