[Libwebsockets] Lightweight JSON parser in C

"Andy Green (林安廸)" andy at warmcat.com
Mon Feb 25 05:08:30 CET 2013


On 25/02/13 02:09, the mail apparently from Edwin van den Oetelaar included:
> Very nice,
> you are very handy with state machines :-)
>
> compiler warned about little thing (sizeof returns size_t, printing
> should be %zu )

Thanks... there were lots more small issues I cleaned as well after 
-Wall, Werror -Wextra --pedantic.  I guess there will be more meddling 
as I use it seriously today.

-Andy

> diff --git a/test.c b/test.c
> index 666af2a..4294567 100644
> --- a/test.c
> +++ b/test.c
> @@ -54,7 +54,7 @@ main(void)
>          fprintf(stderr, "LEJP example app - "
>                  "Copyright (C) 2013 Andy Green <andy at warmcat.com>\n"
>                  "Licensed under LGPL2.1 - usage: cat test4.json | ./lejp\n");
> -       fprintf(stderr, "  sizeof lejp struct: %u\n", sizeof(ctx));
> +       fprintf(stderr, "  sizeof lejp struct: %zu\n", sizeof(ctx));
>
>          lejp_construct(&ctx, parse_callback, NULL, paths, ARRAY_SIZE(paths));
>
>
> On Sun, Feb 24, 2013 at 5:27 PM, "Andy Green (林安廸)" <andy at warmcat.com> wrote:
>> On 23/02/13 09:14, the mail apparently from "Andy Green (林安廸)" included:
>>
>>
>>> I'll post some sample code using a results api when I have it, thanks
>>> for the extra info in the meanwhile.
>>
>>
>> This now exists here:
>>
>> http://git.libwebsockets.org/cgi-bin/cgit/liblejp/
>>
>>  From the README there:
>>
>> Lightweight Embedded JSON Parser
>> =================================
>>
>> Copyright (C) 2013 Andy Green <andy at warmcat.com>
>> Licensed under LGPL2.1
>>
>>
>> Introduction
>> ------------
>>
>> LEJP is an extremely memory-efficient stream parser for JSON written in C.
>>
>>   - Tiny code and memory footprint
>>
>>   - Full compliance with JSON spec, including UTF-8 conversion of unicode
>>          escapes
>>
>>   - As a stream parser, does not require all the JSON to be buffered, but
>> parses
>>          it incrementally as it comes.  This means you can use small or no
>>          input buffers.
>>
>>   - No memory allocations at all in the library - no malloc or free
>>
>>   - Parsed strings passed to user code in buffered (default = 64 byte)
>> chunks,
>>          no limit on total size
>>
>>   - Single < 300 byte context struct holds all parsing state, stacks and
>>          buffers for the lifetime of the parsing action
>>
>>   - Clean for multiple interleaved parsing using different context structs
>>          simultaneously
>>
>>   - Parser calls user callback as parsing progresses, where interesting
>>          information can be acted on or copied for later
>>
>>   - Parsing path is maintained (eg, board[].mux[].sink)
>>
>>   - Array index stack allows easy recovery of "where we are in the arrays"
>> for
>>          multiple array dimensions
>>
>>   - Helper path matching takes an array of "interesting paths" from user code
>>          and efficiently identifies if we are currently parsing on one of
>> these
>>          paths, so user code can understand parsing state
>>
>>   - small types used throughout, pointers avoided for offsets making
>> efficient
>>          memory usage on 64-bit arches
>>
>>   - Limits:
>>
>>          - JSON size: no limit
>>          - String payload size: no limit
>>          - max parsing path: default[1] 128, max 255
>>          - max parsing depth: default[1] 12, max 255
>>          - max array dimensions: default[1] 5, max 255
>>          - string chunk buffer: default[1] 64, max 255
>>          - max user paths for matching: 255
>>          - max members of an array: 65536
>>
>>          [1] Set at compile-time
>>
>>   Build
>>   -----
>>
>>   Currently there's a simple Makefile that generates the test app ./lejp
>>
>>
>>   Test
>>   ----
>>
>>   $ cat test4.json | ./lejp
>>
>>
>>
>> -Andy
>> _______________________________________________
>> Libwebsockets mailing list
>> Libwebsockets at ml.libwebsockets.org
>> http://ml.libwebsockets.org/mailman/listinfo/libwebsockets




More information about the Libwebsockets mailing list