• Stars
    star
    205
  • Rank 191,264 (Top 4 %)
  • Language
    C++
  • License
    MIT License
  • Created about 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Arduino library for parsing potentially huge json streams on devices with scarce memory

json-streaming-parser

Arduino library for parsing potentially huge json streams on devices with scarce memory.

This library is a port of Salsify's PHP based json streaming parser (https://github.com/salsify/jsonstreamingparser).

Why yet another JSON parser?

When working with small (connected) devices you might quickly get to the point where you need to process potentially huge JSON object received from a REST interface. All libraries for processing JSON objects on the Arduino platform had some deficiencies which led me to create one on my own. Not really being an expert in writing parsers I miserably failed the first time.

This is the second attempt and I took Salsify's PHP based parser and ported it to C++. This library has been tested on the Arduino/ESP8266 target platform but should work in theory on all platforms available for the Arduino environment

Why a streaming parser?

Generally speaking when parsing data you have two options to make sense of this data: you either create a document object model (DOM) which contains the whole information of that document and lets you retrieve the nodes with random access. A DOM parser needs the whole document to start parsing and only lets you access the data after it has finished the process. The other option you have when parsing a document is to process it char by char (or byte by byte) while it becomes available to your client code. Compared to the DOM parser this has two advantages: a) you can react the data as soon as meaningful parts are available and b) you can drop information as soon as the parser has processed it. This reduces the memory consumption a lot, especially if you retrieve huge documents when only being interested by a small subset of it. But this efficiency comes at a price: your code will have to do more "magic" than with a DOM parser, the business logic becomes part of the parser.

How to install

Until the library becomes available in the Arduino IDE library manager you'll have to do a bit more work by hand.

  1. Download this library: https://github.com/squix78/json-streaming-parser/archive/master.zip
  2. Rename master.zip to json-streaming-parser.zip
  3. Open the zip file in the Arduino IDE from menu Sketch > Include Library > Add ZIP Library...

How to use

This is a streaming parser, which means that you feed a stream of chars into the parser and you take out from that stream whatever you are interested in. In order to do that you will create a subclass of JsonListener class and implement methods which will be notified in case of certain events in the feed occure. Available events are:

  • startDocument()
  • key(String key)
  • value(String value)
  • endArray()
  • endObject()
  • endDocument()
  • startArray()
  • startObject()

In your implementation of these methods you will have to write problem specific code to find the parts of the document that you are interested in. Please see the example to understand what that means. In the example the ExampleListener implements the event methods declared in the JsonListener interface and prints to the serial console when they are called.

License

This code is available under the MIT license, which basically means that you can use, modify the distribute the code as long as you give credits to me (and Salsify) and add a reference back to this repository. Please read https://github.com/squix78/json-streaming-parser/blob/master/LICENSE for more detail...

Credits

First of all I'd like to thank Salsify for making their PHP parser available to the public. You find their repository here: https://github.com/salsify/jsonstreamingparser

Then I'd like to thank my employer Netcetera (https://github.com/netceteragroup) to let us hackers go twice a year to the CodeCamp and work on software projects like this one.

And last but not least I'd like to thank my wife that she led me spend three days away from the family hacking in the wonderful mountains of Berne.

More Repositories

1

esp8266-projects

C
248
star
2

esp8266-fritzing-parts

Custom ESP8266 based Parts for Fritzing
162
star
3

MAX7219LedMatrix

Library for the ESP8266 on Arduino IDE displaying text on multiple 8x8 led matrices
Objective-C
159
star
4

esp32-mic-fft

Sample code for using the microphone via I2S on a ESP-EYE board
C++
56
star
5

esp8266-weather-station-platformio-demo

Objective-C
48
star
6

esp8266-ci-ota

Example for a continuus delivery by OTA
C++
36
star
7

esp32-tensorflow-microspeech

ESP32 wake word detection with tensor flow
C++
29
star
8

esp8266-getting-started

Exercises to get started with the ESP8266 following the book/workshop
C
28
star
9

esp8266-dht-thingspeak-logger

Logs temperature and humidity to Thingspeak
Arduino
20
star
10

espaper-server-php

PHP server and demo to create json objects for ESP8266 espaper
PHP
15
star
11

extraleague

Company Foosball League App
JavaScript
14
star
12

TTGO-LoRa32-V1.0-TTN-OTAA

Example project to connect the TTGO-LoRa32-V1.0 to TheThingsNetwork over OTAA
C++
10
star
13

esp32-door-sensor

ESP32 project for publishing the door state with a battery driven sensor
C++
9
star
14

ESP8266-lua-nightlight

Nightlight for kids, written in Lua, to run on the nodemcu firmware for ESP8266
Lua
7
star
15

ESP32-Paxcounter-ESPGateway

WiFi/MQTT Code For the ThingPulse ESPGateway
C++
7
star
16

esp8266-oled-ssd1306-font-converter

WebApp to create fonts for the esp8266-oled-ssd1306 library
Java
6
star
17

ePaperDemo1

Objective-C
6
star
18

ILI9341Buffer

Project for developing frame buffer
Objective-C
5
star
19

platformio-test

Objective-C
4
star
20

esp8266-display-tools

Java
3
star
21

esp32-ir-remote-gateway

esp32 firmware to receive IR codes and forward them to a MQTT broker
C++
2
star
22

u8glib

Automatically exported from code.google.com/p/u8glib
C
2
star
23

esp32-icon64-nibbles

nibbles demo for the icon64 3d printing project
C++
1
star
24

node-red-contrib-alexa-tts

node red module for sending voice commands to alexa
HTML
1
star
25

eagle2fritzing-parent

Parent project for converting Eagle brd files to fritzing parts
1
star
26

ESP8266GettingStarted

1
star