0

HTTP GET JSON response

I am trying to figure out how to pull JSON info from a HTTP GET response.

let response := http("GET", url);

 

If the JSON response has both name and values inside " " as if they are all strings, I can pull the value as expected.

if the raw response is:

{"variables": {"temperature": "27.00", "humidity": "60.00"}, "id": "420", "name": "eLabel", "hardware": "esp32", "connected": "true"}

 

Then the following will work:

Temperature := number(response.result.variables.temperature)

 

But if the value is not inside " " because they are numbers, I cannot pull the value unless I do it by substring().

 

If the raw response is:

{"light": 84, "temperature": 25.6, "conductivity": 0, "battery": 100, "moisture": 1}

 

The code below will not work:

Temperature := number(response.result.temperature)

 

What can I do to pull number values from a JSON response that are not sent as a string?

9 replies

null
    • blackie
    • 5 yrs ago
    • Reported - view

    I am still having issues with this.

     

    Ninox seems to be inserting / in front of " in the HTTP response.

     

    This is the raw response from the HTTP GET

    {"light": 705, "moisture": 11, "conductivity": 99, "battery": 99, "temperature": 27.7}

     

    This is how I make the request in the Ninox script:

    let response := http("GET", "http://" + 'IP Address' + "/miflora/" + Identifier);

     

    But Ninox reports response.result as

    {\"light\": 705, \"moisture\": 11, \"conductivity\": 99, \"battery\": 99, \"temperature\": 27.7}

     

    I believe I should be able to use response.result.light , response.result.moisture .... but if I try to use those in an alert I get "undefined".

    • blackie
    • 5 yrs ago
    • Reported - view

    Seems like there is an issue parsing properly formated JSON. If everything is presented as a string it works.

     

    Ninox will parse the the below response correctly, but it is not properly formated JSON. Only string values should be inside double quotes.

    {"variables": {"temperature": "0.00", "humidity": "0.00"}, "id": "420", "name": "eLabel", "hardware": "esp32", "connected": "true"}

    • blackie
    • 5 yrs ago
    • Reported - view

    Seems like there is an issue parsing properly formated JSON. If everything is presented as a string it works.

     

    Ninox will parse the the below response correctly, but it is not properly formated JSON. Only string values should be inside double quotes.

    {"variables": {"temperature": "0.00", "humidity": "0.00"}, "id": "420", "name": "eLabel", "hardware": "esp32", "connected": "true"}

    • blackie
    • 5 yrs ago
    • Reported - view

    Looks like Ninox is parsing most JSON correctly. I can pull everything from this response, number values without double quotes.

    {"variables": {"temperature": 0.00, "humidity": 0.00}, "id": "420", "name": "eLabel", "hardware": "esp32", "connected": true}

     

    But Ninox still won't parse the values for the below JSON, even thought this is the raw(response.result) value:

    {"light": 35, "moisture": 11, "conductivity": 91, "battery": 99, "temperature": 22.6}

     

    I'm not sure what is going on.

    • blackie
    • 5 yrs ago
    • Reported - view

    Looks like Ninox is parsing most JSON correctly. I can pull everything from this response, number values without double quotes.

    {"variables": {"temperature": 0.00, "humidity": 0.00}, "id": "420", "name": "eLabel", "hardware": "esp32", "connected": true}

     

    But Ninox still won't parse the values for the below JSON, even thought this is the raw(response.result) value:

    {"light": 35, "moisture": 11, "conductivity": 91, "battery": 99, "temperature": 22.6}

     

    I'm not sure what is going on.

    • blackie
    • 5 yrs ago
    • Reported - view

    The upstream server providing the response is a mqtt-http-bridge, if that matters.

    https://github.com/njh/mqtt-http-bridge

    • blackie
    • 5 yrs ago
    • Reported - view

    I figured out the issue. The response was valid json, but the response header specified 'text/plain', so Ninox treated it as a string.

    I made a change on line 94  in the file mqtt-http-bridge.rb so the respons header is content-type:application/json

    https://github.com/njh/mqtt-http-bridge/blob/master/mqtt-http-bridge.rb

     

    I changed line 94 to this:

    content_type('application/json')

    • Alexander_Koenig
    • 5 yrs ago
    • Reported - view

    Hi Blackie,

    would you like to show your solution in our API/Zapier workshop:

    Zapier Workshop
    https://zoom.us/webinar/register/WN_tNnu2wwPSHWtwZQvj3egFw

    Best, Alex

    • blackie
    • 5 yrs ago
    • Reported - view

    Hi Alex,

    I would be happy to, but I am not sure which date I will be able to attend the workshop. I have registed, and will try to make it to one of the upcoming workshops.

Content aside

  • 5 yrs agoLast active
  • 9Replies
  • 4482Views