[Libwebsockets] LEJP array of strings

Brice Hamon brice at ydotm.com
Mon Mar 1 16:28:12 CET 2021


I didn't know lws had a Json parser build in :)

On Mon, Mar 1, 2021 at 9:28 AM Andy Green <andy at warmcat.com> wrote:

>
>
> On 3/1/21 2:05 PM, Jean-Paul Saman wrote:
> > Hi,
> >
> > How do I serialize/parse an array of strings with LEJP functions?
> >
> > Here is a JSON snippit I have trouble with to solve with LEJP:
> > [
> >   {
> >     "groups": [ "item1", "item2", "item3" ]
> >   }
> > ]
> >
> > Any pointers/comment/solution are welcome.
>
> If I put your JSON into a file "my.json" verbatim, build current main
> branch lws, and do
>
> $ cat my.json |/projects/libwebsockets/build/bin/libwebsockets-test-lejp
> [2021/03/01 14:24:19:7398] N: libwebsockets-test-lejp  (C) 2017 - 2018
> andy at warmcat.com
> [2021/03/01 14:24:19:7399] N:   usage: cat my.json |
> libwebsockets-test-lejp
>
> [2021/03/01 14:24:19:7399] N: LEJPCB_CONSTRUCTED: path  match 0 statckp 0
> [2021/03/01 14:24:19:7400] N: LEJPCB_START: path  match 0 statckp 0
> [2021/03/01 14:24:19:7400] N: LEJPCB_ARRAY_START: path [] match 0 statckp 2
> [2021/03/01 14:24:19:7400] N:  LEJPCB_OBJECT_START: path [] match 0
> statckp 2
> [2021/03/01 14:24:19:7400] N:   path: '[].groups' (LEJPCB_PAIR_NAME)
> [2021/03/01 14:24:19:7400] N:   LEJPCB_PAIR_NAME: path [].groups match 0
> statckp 9
> [2021/03/01 14:24:19:7400] N:   LEJPCB_ARRAY_START: path [].groups[]
> match 0 statckp 11
> [2021/03/01 14:24:19:7400] N:    LEJPCB_VAL_STR_START: path [].groups[]
> match 0 statckp 11
> [2021/03/01 14:24:19:7400] N:        value 'item1' (array indexes: 0 0 )
>   (LEJPCB_VAL_STR_END)
> [2021/03/01 14:24:19:7401] N:    LEJPCB_VAL_STR_START: path [].groups[]
> match 0 statckp 11
> [2021/03/01 14:24:19:7401] N:        value 'item2' (array indexes: 0 1 )
>   (LEJPCB_VAL_STR_END)
> [2021/03/01 14:24:19:7401] N:    LEJPCB_VAL_STR_START: path [].groups[]
> match 0 statckp 11
> [2021/03/01 14:24:19:7401] N:        value 'item3' (array indexes: 0 2 )
>   (LEJPCB_VAL_STR_END)
> [2021/03/01 14:24:19:7401] N:   LEJPCB_ARRAY_END: path [] match 0 statckp 2
> [2021/03/01 14:24:19:7401] N:  LEJPCB_OBJECT_END: path [] match 0 statckp 2
> [2021/03/01 14:24:19:7401] N: LEJPCB_ARRAY_END: path [] match 0 statckp 2
> [2021/03/01 14:24:19:7401] N: Parsing Completed (LEJPCB_COMPLETE)
> [2021/03/01 14:24:19:7402] N: LEJPCB_COMPLETE: path [] match 0 statckp 2
> [2021/03/01 14:24:19:7402] N: okay (2)
> [2021/03/01 14:24:19:7402] N: LEJPCB_DESTRUCTED: path [] match 0 statckp 2
>
> it seems fine.  Just look at what the test app does, it is very small
> and easy to understand.
>
>
> https://libwebsockets.org/git/libwebsockets/tree/test-apps/test-lejp.c?h=main
>
> -Andy
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20210301/80efb1e1/attachment.htm>


More information about the Libwebsockets mailing list