Parse the response of a JSON REST Webservice

I intend to use a ESP8266 to connect to the internet to get the current time.

GET http://json-time.appspot.com/time.json?tz=Europe/Berlin returns

{
  "tz": "Europe\/Berlin", 
  "hour": 12, 
  "datetime": "Mon, 11 May 2015 12:18:11 +0200", 
  "second": 11, 
  "error": false, 
  "minute": 18
}

Which Library would you advise to use to get the fields hour, minute and second into variables in my sketch?

I managed to communicate with my ESP8266 using AT commands. Also calling the web service worked. But how to automatically do this? Do I have to manually parse the result string (strip the HTTP headers ("Host", "Content-Type", "Content-Length", ...) and parse the JSON)? Or is there a library for that?

Which Library would you advise to use to get the fields hour, minute and second into variables in my sketch?

The stdlib has everything you need, IF you collect that data correctly - as a string.

PaulS:
The stdlib has everything you need, IF you collect that data correctly - as a string.

You mean I have to work with strstr, strtok & friends? :wink:

I'd hoped for some more elaborate JSON libraries.

If you don't want to write it yourself (says a lot about people when they avoid learning/doing things on their own, just saying...) then you need to learn how to look under the right rocks. A quick look at the web location where Arduino code developers keep their libraries ( GITHUB) shows more than one JSON library attempt. I make no recommendation about how good any of the results are, but I have provided a link to the most popular JSON library for Arduino so far.

This is also a topic that has been discussed in this forum... you would have found conversations about it

...and for the record, the advice from PaulS was spot on.

pwillard:
If you don't want to write it yourself (says a lot about people when they avoid learning/doing things on their own, just saying...)

I have written lots of C code in the old days, so no desire to write it myself (why re-invent the wheel?) :wink:

It's a chore - and I had hoped there's already a library for that.

GitHub - bblanchon/ArduinoJson: 📟 JSON library for Arduino and embedded C++. Simple and efficient.

Thanks for the link. After looking into it: It looks quite heavy-weight. Maybe it's really best to do the parsing myself ...

The problem with a general JSON parser is that there is just no way to do it without malloc()ing some memory.

Actually - I tell a lie. It could be done with a stream reader approach. You give the library some callbacks that get invoked at start object/end object and get given the parse stack. A good old LRLA(1) parser.

Hmm.

PaulMurrayCbr:
Actually - I tell a lie. It could be done with a stream reader approach. You give the library some callbacks that get invoked at start object/end object and get given the parse stack. A good old LRLA(1) parser.

Someone said Yacc? ;D