[Libwebsockets] LEJP array of strings

Andy Green andy at warmcat.com
Mon Mar 1 15:28:09 CET 2021



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


More information about the Libwebsockets mailing list