0

{"xx": {"zz": { "yy": "YY", "aa": "AA" }}}

is this a valid json syntax? This was return from a Rest API call. I am trying to parse it using JSON.parse(...) method, but getting "Undefined Token U" error.

I am using it inside servicenow. Not sure if it is a service-now problem or json parsing error.

  • Actual JSON requires those properties to be in double quotes. – StackSlave Dec 04 '20 at 04:02
  • Key names of json objects must be wrapped in `""` so this is not a valid json syntax. But no idea where is that `U` comes from though – Hao Wu Dec 04 '20 at 04:02
  • The input you have doesn't contain the character `U` so it can't be the thing you are parsing that is generating that error. (It's more common to see an error about `u` at the start of `undefined` but you have a capital `U` and I've never seen that before) – Quentin Dec 04 '20 at 13:44

1 Answers1

0

Make sure you're waiting for the response from the API call before trying to parse. Seems like you're attempting to parse before receiving the value, so your variable contains the value undefined. (Could also be caused by a typo in the variable name)

When you try to parse that you'll get an error Unexpected token u in JSON at position 0

If you're new to javascript, consider going through this answer on how to use the Fetch API

Aditya Menon
  • 744
  • 5
  • 13