Examples
Here are the 8 official examples of ArduinoJson. They are available in the "Examples" menu of the Arduino IDE.
StaticJsonBuffer<200> jsonBuffer; JsonObject& root = jsonBuffer.parseObject(json); const char* sensor = root["sensor"]; long time = root["time"]; double latitude = root["data"][0]; double longitude = root["data"][1];StaticJsonBuffer<200> jsonBuffer; JsonObject& root = jsonBuffer.createObject(); root["sensor"] = "gps"; root["time"] = 1351824120; root.printTo(Serial);JSON Generator
This example shows how to generate a JSON document with the ArduinoJson library.
client.println(F("GET /example.json HTTP/1.0")); client.println(F("Connection: close")); client.println(); client.find(endOfHeaders); JsonObject& root = jsonBuffer.parseObject(client);JSON HTTP Client
This example shows how to parse a JSON document in an HTTP response. It uses the Ethernet library, but can be easily adapted for Wifi.
udp.beginPacket(remoteIp, remotePort); root.printTo(udp); udp.println(); udp.endPacket();JSON UDP Beacon
This example shows how to send a JSON document to a UDP socket. It uses the Ethernet library but could easily be changed to support Wifi.
client.println("HTTP/1.0 200 OK"); client.println("Content-Type: application/json"); client.println(); root.prettyPrintTo(client); client.stop();JSON HTTP Server
This example shows how to implement an HTTP server that sends JSON document in the responses.
File file = SD.open(filename); JsonObject &root = jsonBuffer.parseObject(file) file.close(); config.port = root["port"] | 2731;JSON Configuration File
This example shows how to store your project configuration in a file. It uses the SD library but can be easily modified for any other file-system.
long time = obj[String("time")]; obj[String("time")] = time; String sensor = obj["sensor"]; sensor = obj["sensor"].as<String>();String objects and ArduinoJson
This example shows the different ways you can use String objects with ArduinoJson.
long time = obj[F("time")]; obj[F("time")] = time; obj["sensor"] = F("gps"); obj["sensor"] = serialized(F("\"gps\""));Flash strings and ArduinoJson
This example shows the different ways you can use Flash strings (PROGMEM) with ArduinoJson.