ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
json.h File Reference

Layer 6 (Presentation) - zero-heap JSON: a bounded writer and top-level reader. More...

#include "protocore_config.h"

Go to the source code of this file.

Detailed Description

Layer 6 (Presentation) - zero-heap JSON: a bounded writer and top-level reader.

A deliberately small JSON helper for the common IoT shapes (a flat-ish object of strings / numbers / booleans, with bounded nesting). It allocates nothing: the writer formats into a caller-provided buffer, and the reader scans a NUL-terminated body in place. ArduinoJson remains the option when you need a full DOM - it heap-allocates, which this library avoids.

Writing

char buf[128];
protocore_json_writer w;
Json.init(&w, buf, sizeof(buf));
Json.begin_object(&w);
Json.kv_str(&w, "status", "ok");
Json.kv_int(&w, "count", 3);
Json.key(&w, "items"); Json.begin_array(&w);
Json.put_str(&w, "a"); Json.put_str(&w, "b");
Json.end_array(&w);
Json.end_object(&w);
if (protocore_json_ok(&w)) server.send(slot, 200, "application/json", protocore_json_c_str(&w));
// -> {"status":"ok","count":3,"items":["a","b"]}

Reading (top-level keys of an object body)

char ssid[33];
if (Json.get_str(req->body, "ssid", ssid, sizeof(ssid))) { ... }
long port;
if (Json.get_int(req->body, "port", &port)) { ... }

Definition in file json.h.