I need to parse JSON string.
I’ve tried JSON.stringify
and then JSON.parse
below sample string, but server performed escape sequencing
I used str.replace('/\/g','')
to remove the escape sequence but that doesnt help because if you look in the "default_request"
key is wraps its value with ""
which is doesnt allow me parse it using JSON.parse()
JavaScript
x
8
1
{
2
"request": {
3
"service_name": "authService",
4
"url": "https://some-url.com/{accounts}",
5
"default_request": "{"authMethod":"somename","multiCheck":false}"
6
}
7
}
8
so I tried to replace "{
with {
and }"
with }
JavaScript
1
2
1
str.replace('/"{/g','{')).replace('/}"/g','}'))
2
but it creates another problem.
JavaScript
1
9
1
Favourable condition
2
{
3
"request": {
4
"service_name": "authService",
5
"url": "https://some-url.com/{accounts}",
6
"default_request": {"authMethod":"somename","multiCheck":false}
7
}
8
}
9
Advertisement
Answer
default_request was stringifyied twice. to fix it, try this
JavaScript
1
2
1
jsonObject.request.default_request = JSON.parse(jsonObject.request.default_request);
2