[Libwebsockets] Lightweight JSON parser in C

"Andy Green (林安廸)" andy at warmcat.com
Sun Feb 24 17:27:22 CET 2013

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:


 From the README there:

Lightweight Embedded JSON Parser

Copyright (C) 2013 Andy Green <andy at warmcat.com>
Licensed under LGPL2.1


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

  - 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) 
  	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
  - 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 
  	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 
  	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


  Currently there's a simple Makefile that generates the test app ./lejp


  $ cat test4.json | ./lejp


More information about the Libwebsockets mailing list