After using http:get(), I receive back a string from picking the "content" from the hash:
response = http:get(webservice_url, {"key1": value1, "key2": value2});
json_resp = response.pick("$..content");
However, since json_resp is a string and not an actual JSON object, I can't run a command like this:
value = json_resp.pick("$..string");
Is there a way to tell KRL that I want to parse json_resp as JSON? An eval() or something, perhaps?
The decode() operator does just what you want. It operates on a JSON string, attempting to convert it to a native KRL object. Note that KRL also has encode() which operates on a native KRL object and returns a JSON string representation of that object.
response = http:get(webservice_url, {"key1": value1, "key2": value2});
json_resp = response.pick("$..content").decode();
value = json_resp.pick("$..string");
// will work since json_resp is now a native KRL object
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With