MCPcopy Create free account
hub / github.com/bblanchon/ArduinoJson / main

Function main

extras/scripts/wandbox/JsonGeneratorExample.cpp:10–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#include "ArduinoJson.h"
9
10int main() {
11 // Allocate the JSON document
12 JsonDocument doc;
13
14 // Add values in the document.
15 doc["sensor"] = "gps";
16 doc["time"] = 1351824120;
17
18 // Add an array
19 JsonArray data = doc["data"].to<JsonArray>();
20 data.add(48.756080);
21 data.add(2.302038);
22
23 // Generate the minified JSON and send it to STDOUT
24 serializeJson(doc, std::cout);
25 // The above line prints:
26 // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}
27
28 // Start a new line
29 std::cout << std::endl;
30
31 // Generate the prettified JSON and send it to STDOUT
32 serializeJsonPretty(doc, std::cout);
33 // The above line prints:
34 // {
35 // "sensor": "gps",
36 // "time": 1351824120,
37 // "data": [
38 // 48.756080,
39 // 2.302038
40 // ]
41 // }
42}

Callers

nothing calls this directly

Calls 2

serializeJsonFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected