Another Parsing JSON Question!


#1

I’m attempting to parse some JSON that I have in a string variable. I’ve tried valid JSON.

For example the data returned by:

http://api.wunderground.com/api/Your_Key/conditions/q/CA/San_Francisco.json

Except instead of calling the URL I am just pasting the value in. I’m not actually trying to call this API, I want to pass the JSON to a piston as a variable which is why I’m testing this out. Anyways, it fails every time. Much simpler JSON also fails.

9/13/2018, 4:34:00 PM +932ms
+207ms	║Invalid ternary operator. Ternary operator's syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+217ms	║Invalid ternary operator. Ternary operator's syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+229ms	║Invalid ternary operator. Ternary operator's syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+237ms	║Invalid ternary operator. Ternary operator's syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+254ms	║Invalid ternary operator. Ternary operator's syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+266ms	║Invalid ternary operator. Ternary operator's syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+275ms	║Invalid ternary operator. Ternary operator's syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+313ms	║Invalid ternary operator. Ternary operator's syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+341ms	║Invalid ternary operator. Ternary operator's syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+367ms	║Invalid ternary operator. Ternary operator's syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.

#2

You will need to use a backslash \ to escape all {}\ characters in the JSON. Since all strings in webCoRE support { variableName } interpolated values it ends up trying to handle your JSON as if it were a webCoRE expression.

For example, { "response": { "version": "0.1" } } will need to be written as \{ "response": \{ "version": "0.1" \} \}. Then you should be able to use the Parse JSON string action and interact with the data via the $json system variable (e.g. $json.response.version).


#3

Well shit, that isn’t going to work. It would be a pain to type all of the escape characters. Oh well, I was just avoiding becoming a regular expressions expert. Now will have to do that.


#4

A little late to the party but:

Set variable {myJson} = replace(replace(replace({$response}, “”, “\”),"{", “{”), “}”, “}”)