Skip to content
Advertisement

Need to parse JSON string with value is quoted curly braces

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()

    {
      "request": {
        "service_name": "authService",
        "url": "https://some-url.com/{accounts}",
        "default_request": "{"authMethod":"somename","multiCheck":false}"
        }
    }

so I tried to replace "{ with { and }" with }

str.replace('/"{/g','{')).replace('/}"/g','}'))

but it creates another problem.

Favourable condition
    {
      "request": {
       "service_name": "authService",
       "url": "https://some-url.com/{accounts}",
       "default_request": {"authMethod":"somename","multiCheck":false}
      }
    }

Advertisement

Answer

default_request was stringifyied twice. to fix it, try this

jsonObject.request.default_request = JSON.parse(jsonObject.request.default_request);
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement