LwJSON latest-develop documentation

Welcome to the documentation for version latest-develop.

LwJSON is a generic JSON parser library optimized for embedded systems.

_images/logo.svg

Features

  • Written in C (C11), compatible with size_t for size data types

  • RFC 4627 and RFC 8259 compliant

  • Based on static token allocation with optional application dynamic pre-allocation

  • No recursion during parse operation

  • Re-entrant functions

  • Zero-copy, no malloc or free functions used

  • Supports streaming parsing as secondary option

  • Optional support for inline comments with /* comment… */ syntax between any blank region of input string

  • Advanced find algorithm for tokens

  • Tests coverage is available

  • User friendly MIT license

Requirements

  • C compiler

  • Few kB of ROM memory

Contribute

Fresh contributions are always welcome. Simple instructions to proceed:

  1. Fork Github repository

  2. Respect C style & coding rules used by the library

  3. Create a pull request to develop branch with new features or bug fixes

Alternatively you may:

  1. Report a bug

  2. Ask for a feature request

Example code

Example code
 1#include <stdio.h>
 2#include "lwjson/lwjson.h"
 3
 4/* LwJSON instance and tokens */
 5static lwjson_token_t tokens[128];
 6static lwjson_t lwjson;
 7
 8/* Parse JSON */
 9void
10example_minimal_run(void) {
11    lwjson_init(&lwjson, tokens, LWJSON_ARRAYSIZE(tokens));
12    if (lwjson_parse(&lwjson, "{\"mykey\":\"myvalue\"}") == lwjsonOK) {
13        const lwjson_token_t* t;
14        printf("JSON parsed..\r\n");
15
16        /* Find custom key in JSON */
17        if ((t = lwjson_find(&lwjson, "mykey")) != NULL) {
18            printf("Key found with data type: %d\r\n", (int)t->type);
19        }
20
21        /* Call this when not used anymore */
22        lwjson_free(&lwjson);
23    }
24}

License

MIT License

Copyright (c) 2024 Tilen MAJERLE

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.