[Libwebsockets] LEJP array parsing

Andy Green andy at warmcat.com
Sat Nov 6 09:26:15 CET 2021

On 11/4/21 12:05, Aurélien Vallée wrote:
> Say I have the following JSON object:
> {
>      "array1": [["a", "b"], ["c", "d"]],
>      "array2": [["e", "f"], ["g", "h"]]
> }
> I am trying to parse it with LEJP without having to re-implement 
> stateful array parsing in my callback.

You're doing the right things, but lejp needs more love to support what 
you want.  I pushed some patches on main that...

a) add support for leading wildcards in path matches, like "*[]"

b) add a .flags in the lejp ctx that lets you elect to have breaking 
features in the context, and define a flag LEJP_FLAG_FEAT_OBJECT_INDEXES
that tracks indexes for hierarchies of { x, y, z } the same as [ x, y, z 
].  This also fixes the 2 / 3 level problem you found, without the flag 
it partly understands { , } index tracking, but only because it saw a 
comma.  The flag makes it understand { represents an index level by 
itself too.  This flags field gives us a way to keep evolving lejp 
without causing trouble for people who are not hitting the problems 
being fixed.

c) Improve the unit test for lejp to check the parsing results for the 
tests, and check your case both without (for backwards compatibility) 
and with the new flag

d) Add some docs in the README about it

> Also, I did not find where in the callback I could retrieve the array 
> indexes, which would be very helpful during parsing

It is in the README now, ctx->ipos is the depth of the indexable 
hierarchy and ctx->i[] are the (uint16_t) counts for each level.


More information about the Libwebsockets mailing list