[Libwebsockets] LEJP array parsing

Aurélien Vallée vallee.aurelien at gmail.com
Thu Nov 4 13:05:51 CET 2021


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.

Basically, I would like to retrieve from the context both
   1) whether I am currently parsing "array1" or "array2"
   2) whether I am inside a subarray of "array1" or "array1" itself

I struggle to properly configure the paths to give LEJP to identify e.g.
"an array inside array1".

Here is the result of libwebsockets-test-lejp:

[2021/11/04 20:01:08:7962] N: LEJPCB_CONSTRUCTED: path  match 0 statckp 0
[2021/11/04 20:01:08:7962] N: LEJPCB_START: path  match 0 statckp 0
[2021/11/04 20:01:08:7962] N: LEJPCB_OBJECT_START: path  match 0 statckp 0
[2021/11/04 20:01:08:7962] N: path: 'array1' (LEJPCB_PAIR_NAME)
[2021/11/04 20:01:08:7962] N: LEJPCB_PAIR_NAME: path array1 match 0 statckp
6
[2021/11/04 20:01:08:7962] N: LEJPCB_ARRAY_START: path array1[] match 0
statckp 8
[2021/11/04 20:01:08:7962] N:  LEJPCB_ARRAY_START: path array1[][] match 0
statckp 10
[2021/11/04 20:01:08:7962] N:   LEJPCB_VAL_STR_START: path array1[][] match
0 statckp 10
[2021/11/04 20:01:08:7962] N:       value 'a' (array indexes: 0 0 )
 (LEJPCB_VAL_STR_END)
[2021/11/04 20:01:08:7962] N:   LEJPCB_VAL_STR_START: path array1[][] match
0 statckp 10
[2021/11/04 20:01:08:7962] N:       value 'b' (array indexes: 0 1 )
 (LEJPCB_VAL_STR_END)
[2021/11/04 20:01:08:7962] N:  LEJPCB_ARRAY_END: path array1[] match 0
statckp 8
[2021/11/04 20:01:08:7962] N:  LEJPCB_ARRAY_START: path array1[][] match 0
statckp 10
[2021/11/04 20:01:08:7962] N:   LEJPCB_VAL_STR_START: path array1[][] match
0 statckp 10
[2021/11/04 20:01:08:7962] N:       value 'c' (array indexes: 1 0 )
 (LEJPCB_VAL_STR_END)
[2021/11/04 20:01:08:7962] N:   LEJPCB_VAL_STR_START: path array1[][] match
0 statckp 10
[2021/11/04 20:01:08:7962] N:       value 'd' (array indexes: 1 1 )
 (LEJPCB_VAL_STR_END)
[2021/11/04 20:01:08:7962] N:  LEJPCB_ARRAY_END: path array1[] match 0
statckp 8
[2021/11/04 20:01:08:7962] N: LEJPCB_ARRAY_END: path array1[] match 0
statckp 8
[2021/11/04 20:01:08:7962] N: path: 'array2' (LEJPCB_PAIR_NAME)
[2021/11/04 20:01:08:7962] N: LEJPCB_PAIR_NAME: path array2 match 0 statckp
6
[2021/11/04 20:01:08:7962] N: LEJPCB_ARRAY_START: path array2[] match 0
statckp 8
[2021/11/04 20:01:08:7962] N:  LEJPCB_ARRAY_START: path array2[][] match 0
statckp 10
[2021/11/04 20:01:08:7962] N:   LEJPCB_VAL_STR_START: path array2[][] match
0 statckp 10
[2021/11/04 20:01:08:7963] N:       value 'e' (array indexes: 1 0 0 )
 (LEJPCB_VAL_STR_END)
[2021/11/04 20:01:08:7963] N:   LEJPCB_VAL_STR_START: path array2[][] match
0 statckp 10
[2021/11/04 20:01:08:7963] N:       value 'f' (array indexes: 1 0 1 )
 (LEJPCB_VAL_STR_END)
[2021/11/04 20:01:08:7963] N:  LEJPCB_ARRAY_END: path array2[] match 0
statckp 8
[2021/11/04 20:01:08:7963] N:  LEJPCB_ARRAY_START: path array2[][] match 0
statckp 10
[2021/11/04 20:01:08:7963] N:   LEJPCB_VAL_STR_START: path array2[][] match
0 statckp 10
[2021/11/04 20:01:08:7963] N:       value 'g' (array indexes: 1 1 0 )
 (LEJPCB_VAL_STR_END)
[2021/11/04 20:01:08:7963] N:   LEJPCB_VAL_STR_START: path array2[][] match
0 statckp 10
[2021/11/04 20:01:08:7963] N:       value 'h' (array indexes: 1 1 1 )
 (LEJPCB_VAL_STR_END)
[2021/11/04 20:01:08:7963] N:  LEJPCB_ARRAY_END: path array2[] match 0
statckp 8
[2021/11/04 20:01:08:7963] N: LEJPCB_ARRAY_END: path array2[] match 0
statckp 8
[2021/11/04 20:01:08:7963] N: LEJPCB_OBJECT_END: path array2[] match 0
statckp 8
[2021/11/04 20:01:08:7963] N: Parsing Completed (LEJPCB_COMPLETE)
[2021/11/04 20:01:08:7963] N: LEJPCB_COMPLETE: path array2[] match 0
statckp 8
[2021/11/04 20:01:08:7963] N: okay (2)
[2021/11/04 20:01:08:7963] N: LEJPCB_DESTRUCTED: path array2[] match 0
statckp 8

I am only interested by the values in the subarrays of "array1" and
"array2" (which have a fixed, known count).

However, any variation of "array1[]", "array1[][]" does not match anything.
The only thing I manage to match is "array1" and "array2", but it's not
very convenient because then I have to differentiate between the outter and
inner arrays.

The documentation mentions support for fancy path selector like
"retry[].*.backoff".

Also, I did not find where in the callback I could retrieve the array
indexes, which would be very helpful during parsing (and why is there 2
indexes for array1 and 3 for array2?)
-- 
Aurélien Vallée
Phone +33 9 77 19 85 61
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20211104/a45e5ec4/attachment.htm>


More information about the Libwebsockets mailing list