Last active
January 4, 2020 15:36
-
-
Save bblanchon/e8ba914a7109f3642c0f to your computer and use it in GitHub Desktop.
Comparision of JSON parsing libraries for Arduino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <aJSON.h> | |
char json[] = "{\"sensor\":\"outdoor\",\"value\":25.6}"; | |
void setup() | |
{ | |
Serial.begin(9600); | |
Serial.println(json); | |
aJsonObject* root = aJson.parse(json); | |
aJsonObject* name = aJson.getObjectItem(root, "sensor"); | |
aJsonObject* value = aJson.getObjectItem(root, "value"); | |
Serial.println(name->valuestring); | |
Serial.println(value->valuefloat); | |
aJson.deleteItem(root); | |
} | |
void loop() | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <JsonParser.h> | |
using namespace ArduinoJson::Parser; | |
char json[] = "{\"sensor\":\"outdoor\",\"value\":25.6}"; | |
void setup() | |
{ | |
Serial.begin(9600); | |
Serial.println(json); | |
JsonParser<10> parser; | |
JsonHashTable hashTable = parser.parseHashTable(json); | |
Serial.println(hashTable.getString("sensor")); | |
Serial.println(hashTable.getDouble("value")); | |
} | |
void loop() | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <JsonParser.h> | |
using namespace ArduinoJson::Parser; | |
char json[] = "{\"sensor\":\"outdoor\",\"value\":25.6}"; | |
void setup() | |
{ | |
Serial.begin(9600); | |
Serial.println(json); | |
JsonParser<10> parser; | |
JsonObject root = parser.parse(json); | |
Serial.println((char*)root["sensor"]); | |
Serial.println((double)root["value"]); | |
} | |
void loop() | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <json_arduino.h> | |
char json[] = "{\"sensor\":\"outdoor\",\"value\":25.6}"; | |
void setup() | |
{ | |
Serial.begin(9600); | |
Serial.println(json); | |
token_list_t* token_list = create_token_list(20); | |
json_to_token_list(json, token_list); | |
Serial.println(json_get_value(token_list,"sensor")); | |
Serial.println(atof(json_get_value(token_list,"value"))); | |
release_token_list(token_list); | |
} | |
void loop() | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char json[] = "{\"sensor\":\"outdoor\",\"value\":25.6}"; | |
void setup() | |
{ | |
Serial.begin(9600); | |
Serial.println(json); | |
Serial.println("outdoor"); | |
Serial.println(25.6); | |
} | |
void loop() | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment