What parser can I use for JSON?

Hi,
I want to deal within my Photon project with JSON file. The idea is that Photon can receive string of JSON, and then retrive the different value in that file. For example I send:

{"type": "myType","value": "theValue"}

Then I want within my software to retrive with a solution similar to this one:

String type = JSON.PARSER["type"];
String value = JSON.PARSER["value"];

How Can I do ?

You could start by looking if there was a library dealing with this in Web IDE :wink:
https://build.particle.io/libs/54d540fb4898cda9dc00077b

2 Likes

@zebrone92, I’m using that lib presently for both encoding and decoding JSON. It works quite well and the author is actively supporting it. Note that the version on the IDE (I suspect 4.x) is not the latest (5.1). :wink:

1 Like

And don’t forget the github documentation

3 Likes

A quick update for those using this library with the standalone Particle IDE and using the source from GIT.

If you get the error: “SparkJson.h: No such file or directory”, this is because the Particle IDE expects libraries to be in this structure:

MyProject
    lib
        SparkJson
            src
    src

By renaming the SparkJson subfolder “firmware” folder to “src”, you’ll get rid of this error.

If you get the error “JsonServer.ino:6:22: fatal error: Ethernet.h: No such file or directory” it’s because the Particle IDE dislikes the “examples” folder inside the “src” folder (the one you renamed from “firmware” above). Just move the Examples folder out of the “src” folder to solve this.

For some reason, the author has an .ino file in the middle of the source code? This causes the Particle IDE to complain with an error like this:

In function `setup’: lib/SparkJson/src/my-core.ino:9: multiple definition of ‘setup’

Just delete the file “my-core.ino” from your source folder and your project should compile.

Note: the memory footprint for this library is surprisingly large at 15 820 bytes (using 200 char static buffer). The ArduinoJson library is only 8 588 bytes (using same buffer size) and seems better maintained.

@jenschr, @rickkas7 published a new JSON generator/parser library that may be worth looking at:

https://build.particle.io/libs/JsonParserGeneratorRK

:slight_smile:

2 Likes

JsonParserGeneratorRK4 looks like the better option, so I’ll go for that! Gotta say that @rickkas7 have saved me a couple times now. I’ve gotta buy him some beers when I meet him! :slight_smile:

(Sorry for reviving an old thread, but it comes up first in search so I figured that I could just as well keep it updated)

2 Likes