ParseJSON - Forum

Forum Navigation
You need to log in to create posts and topics.

ParseJSON

CreateEmptyObject [myjson]
.SetVar [myjson] "{'name':'John','age':30,'city':'NewYork'}"
ParseJSON "{'name':'John', 'age':30, 'city':'New York'}" [myjson]

MessageBox "Hello" "My Name is [myjson.name] and age is [myjson.age]" "<b>Ok</b>|Cancel" ""

In the code above the SetVar  version works but the ParseJSON  version not. It throws a syntax error: Expected property name or '}' in JSON position 1 at JSON.parse

 

The JSON standard requires double quotes for property names and values, even though in JavaScript code you can use which ever is most convenient. Try changing your action to this:

ParseJSON '{"name": "John","age": 30,"city": "New York"}' [myjson]

The example in the ParseJSON entry of the Help is incorrect and so needs to be updated to stop misleading users. @luishp

 

 

luishp and kajanken have reacted to this post.
luishpkajanken

ParseJSON action wizard do not work properly and SetVar does not accept single quotes around json string.  I think the JSON syntax should be same everywhere.

luishp and susan have reacted to this post.
luishpsusan

I agree that it is a problem, I too have spent time trying to figure out what's wrong in a similar script situation until I understood what was going on and realised  the solution.

luishp has reacted to this post.
luishp

@kajanken, @susan

JSON requires double quotes (") for both property names and string values within objects. Using single quotes (') around property names and string values will result in invalid JSON.

I know the help file sample is incorrect. I will fix it as soon as possible.
Sorry for the inconveniences.