ArduinoJsonWriter
A lightweight library to make it easy to generate json document on Arduino board
Install / Use
/learn @timnew/ArduinoJsonWriterREADME
ArduinoJsonWriter
Json Writer is a light weight library that make it easier to generate json document on Arduino.
The library works pretty similar to the SAX for XML, it treats JSON as a stream of nodes. With the API, you can compose a JSON document by emitting each node.
Initialize JsonWriter
JsonWriter wraps a Stream instance, so it could be used to generate data for all kind of Stream based IO or starages, including: Serial, Wire(I2C), Ethernet TCP socket, SD
JsonWriter serialJsonWriter(Serial);
JsonWriter wireJsonWriter(Wire);
JsonWriter ethernetJsonWriter1(ethernetClient);
JsonWriter ethernetJsonWriter2(ethernetServer);
Usage
Emit Primitives
writer.string("Json String"); // "Json String"
writer.string("0x" + String(255,HEX)); // "0xFF"
writer.number(23); // 23
writer.null(); // null
writer.boolean(true); // true
writer.boolean(false); // false
Emit Array
writer
.beginArray()
.string("alpha")
.string("beta")
.null()
.string("gamma")
.number(123)
.endArray();
// ["aplha","beta",null,"gamma",123]
Emit Object
writer
.beginObject()
.property("Real name","Thomas A. Anderson")
.property("Hacker name","Neo")
.property("Entity","The One")
.property("Height",185)
.property("isCreatedByArchitect",true)
.endObject();
// {"Real name":"Thomas A. Anderson","Hacker name":"Neo","Entity":"The One","Height":185,"isCreatedByArchitect":true}
Array of objects
writer
.beginArray()
.beginObject()
.property("name", "alpha")
.endObject()
.beginObject()
.property("name", "beta")
.property("anotherProperty", 12.67)
.endObject()
.beginObject()
.property("name", "gamma")
.endObject()
.endArray();
// [{"name":"alpha"},{"name":"beta","anotherProperty":12.67},{"name":"gamma"}]
Nested Objects and arrays
writer
.beginObject()
.property("id", 7)
.beginObject("name")
.property("firstName","James")
.property("lastName","Bond")
.endObject()
.beginArray("languages")
.string("English")
.string("Russian")
.endArray()
.beginArray("gadgets")
.beginObject()
.property("name", "Laser watch")
.property("returned", false)
.endObject()
.beginObject()
.property("name", "Walther PP")
.property("returned", false)
.beginArray("calibers")
.number(32)
.number(380)
.number(22)
.endArray()
.endObject()
.endArray()
.endObject();
// {"id":7,"name":{"firstName":"James","lastName":"Bond"},"languages":["English","Russian"],"gadgets":[{"name":"Laser watch","returned":0},{"name":"Walther PP","returned":0,"calibers":[32,380,22]}]}
Related Skills
node-connect
341.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
341.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.6kCommit, push, and open a PR
