JSON Parse Java-Script

Hello,
I have a question about Java-Script and JSON. It looks like that JSON.parse in Java-Script has many problems with escaped strings.
Anybody knows a solution how to work in Java-Script with JSON strings that works everywhere but not in Java-Script?

[{"id_case":"589","body_case":"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"  xmlns:tns=\"http:\/\/kd.blum.com\/api?ws=1\"><soap:Body><tns:initiateCorpus><initiateCorpus><ruleset>MR_Ruleset_Placeholder<\/ruleset><\/initiateCorpus><\/tns:initiateCorpus><\/soap:Body><\/soap:Envelope>"},{"id_case":"590","body_case":"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"  xmlns:tns=\"http:\/\/136.243.36.137:8082\/api?ws=1\"><soap:Body><tns:addFront><addFront><corpus><id>MR17090144d5a674a762c4a1c7f8e2afa838cb0559ad1fe8dda2b<\/id><\/corpus><containerNumber>1.1.1<\/containerNumber><position>front<\/position><\/addFront><\/tns:addFront><\/soap:Body><\/soap:Envelope>"},{"id_case":"591","body_case":"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"  xmlns:tns=\"http:\/\/136.243.36.137:8082\/api?ws=1\"><soap:Body><tns:getCorpus><getCorpus><corpus>MR17090144d5a674a762c4a1c7f8e2afa838cb0559ad1fe8dda2b<\/corpus><\/getCorpus><\/tns:getCorpus><\/soap:Body><\/soap:Envelope>"},{"id_case":"592","body_case":"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"  xmlns:tns=\"http:\/\/136.243.36.137:8082\/api?ws=1\"><soap:Body><tns:alterMultipleCorpusParameter><alterMultipleCorpusParameterById><corpus>MR17090144d5a674a762c4a1c7f8e2afa838cb0559ad1fe8dda2b<\/corpus><parameterValues><items><key>CorpusTopPanel_space_above<\/key><value>-1<\/value><type>Grundeinstellungen<\/type><\/items><\/parameterValues><\/alterMultipleCorpusParameterById><\/tns:alterMultipleCorpusParameter><\/soap:Body><\/soap:Envelope>"},{"id_case":"593","body_case":"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"  xmlns:tns=\"http:\/\/136.243.36.137:8082\/api?ws=1\"><soap:Body><tns:getCorpus><getCorpus><corpus>MR17090144d5a674a762c4a1c7f8e2afa838cb0559ad1fe8dda2b<\/corpus><\/getCorpus><\/tns:getCorpus><\/soap:Body><\/soap:Envelope>"}]

Open in new window

In Java-Script only the Ruleset value "MR_Ruleset_Placeholder" is shown finally.
Ingo FoersterProgrammerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
your JSON look fine, why do you want to parse it ? how do you receive the data ?
0
Ingo FoersterProgrammerAuthor Commented:
I try to load the data to a ui control. This control use JavaScript JSON.parse. And this makes me trouble. I really do not understand this, so I hope there is a workaround for this.
0
Flabio GatesCommented:
Try doubling your backslashes. See fiddle here.
var s = '[{"id_case":"42","body_case":"<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>"}]';
var d = JSON.parse(s);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
According to this site https://jsonformatter.curiousconcept.com/ your JSON is valid.

It all depends on how your JSON is getting into your application. If you put that JSON into a file data.json and then load it with jQuery's getJSON() function there is no problem with it.

If you try and assign it to a JavaScript variable and then pass that to JSON.parse it will have a problem because of the \" in the string

Bottom line - if you are passing that JSON as a string declared within the application you will have to escape the strings as pointed out in Flabio's post
0
Ingo FoersterProgrammerAuthor Commented:
Thank you very much, this helped me a lot
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.