Skip to main content

jsmn-json-parse

:::warning [UNTESTED] native_sim build + run PASSED locally, but this has not been verified on real silicon (no bench / HiL sweep). :::

Tokenize an embedded JSON config into a typed struct with jsmn v1.1.0 (MIT) — a minimalist, allocation-free JSON tokenizer.

Source: examples/connectivity/jsmn-json-parse/.

What it does

  1. jsmn_init() / jsmn_parse() a fixed in-RAM JSON string into a fixed-size jsmntok_t[].
  2. Walks the flat token array as key/value pairs.
  3. Extracts a device string and an interval_ms int into a struct, then prints them.

jsmn does not build a tree or allocate — it emits a flat array of token spans into a buffer you size, which is exactly why it suits an MCU. The whole point of the example is proving the library works before you point it at a real payload (a sensor-config blob, a cloud response, …).

jsmn is a vendored single header (vendors/jsmn/include/jsmn.h), not a west-fetched module, so the example's CMakeLists.txt adds that include directory directly. libraries: [jsmn] emits CONFIG_ALP_JSMN_SW=y — jsmn is pure software, with no accelerator class.

board.yaml

libraries:
- name: jsmn
cores: [m55_hp]

som:
sku: E1M-AEN801

preset: e1m-evk

cores:
m55_hp:
app: ./src
peripherals: []

diagnostics:
log_level: info

This example does no I/O — swap som.sku to any SoM/preset pair (e.g. E1M-V2N101 / e1m-x-evk) and it still builds. No peripheral or board-specific macro is involved.

Expected output

[jsmn-json-parse] parsed 7 tokens
[jsmn-json-parse] device = "e1m-aen801"
[jsmn-json-parse] interval_ms = 500
[jsmn-json-parse] done

See also

Questions about this page? Discuss in Community Forum