user1020015 user1020015 - 1 year ago 324
JSON Question

Error running example ArduinoJson

I am having trouble running a example from

I already installed the library and ran a simple example.

* Arduino JSON library - Parser Example
* Benoit Blanchon 2014 - MIT License

#include <JsonParser.h>

using namespace ArduinoJson::Parser;

void setup()

char json [] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
JsonParser<16> parser;
JsonObject root = parser.parse(json);

if (!root.success())
Serial.println("JsonParser.parse() failed");

char* sensor = root["sensor"];
long time = root["time"];
double latitude = root["data"][0];
double longitude = root["data"][1];

Serial.println(latitude, 6);
Serial.println(longitude, 6);

void loop()

But I am getting this error:

JsonParserExample:8: error: 'ArduinoJson' has not been declared
JsonParserExample:8: error: 'Parser' is not a namespace-name
JsonParserExample:8: error: expected namespace-name before ';' token
JsonParserExample.ino: In function 'void setup()':
JsonParserExample:18: error: 'JsonObject' was not declared in this scope
JsonParserExample:18: error: expected `;' before 'root'
JsonParserExample:20: error: 'root' was not declared in this scope
JsonParserExample:26: error: 'root' was not declared in this scope

There seems to be a problem with the namespace but I can't find it..

Answer Source

I tried downloading it and it works. I'm using Arduino IDE 1.0.5 r2.

Did you correctly "install" the library? I mean

  1. Download the archive from github (e.g. by clicking "Download ZIP", on the right)
  2. Extract the content to the "libraries" folder inside the sketch folder
  3. Rename the folder in "ArduinoJson"
  4. Start Arduino IDE

At the third point you should have the files

<your sketch dir>\libraries\ArduinoJson\ArduinoJson.sln
<your sketch dir>\libraries\ArduinoJson\
<your sketch dir>\libraries\ArduinoJson\JsonParser\JsonParser.vcxproj
and so on

If you did everything in the correct way in Arduino IDE you should see, under File->Examples, the ArduinoJson folder and, inside, two examples.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download