parsing the end of json

17 views
Skip to first unread message

Marty Leisner

unread,
Nov 30, 2022, 3:14:39 PM11/30/22
to Jansson users
I have a network connection throwing json at me.
I don't want to do blocking calls.

I suppose I need to do chunking myself and start counting {} to pass to jansson a
"single json frame" to decode.

Any simpler ways?

marty

Basile Starynkevitch

unread,
Nov 30, 2022, 4:11:43 PM11/30/22
to Marty Leisner, Jansson users


On 11/30/22 21:14, Marty Leisner wrote:
I have a network connection throwing json at me.
I don't want to do blocking calls.

I suppose I need to do chunking myself and start counting {} to pass to jansson a
"single json frame" to decode.


If both the JSON emitter and receiver are open source, or you are allowed to modify their code, you could adopt a simple convention. That every JSON frame is ended by a formfeed character.

PS. My pet open source (embryonic) project (using JSON and jsoncpp) is RefPerSys (an open source inference engine for expert systems).


-- 
Basile Starynkevitch                  <bas...@starynkevitch.net>
(only mine opinions / les opinions sont miennes uniquement)
92340 Bourg-la-Reine, France
web page: starynkevitch.net/Basile/

marty leisner

unread,
Nov 30, 2022, 6:05:46 PM11/30/22
to Basile Starynkevitch, Jansson users
I'm writing both sides and inventing my own protocol.    Seems I can delimit json frames with non-ascii character (could be a formfeed).    I still have to develop psuedostreams to "keep" what was read until I hit the delimiting character (then throw it away).

Easier than counting braces.

thanks...

marty
 

Richard Mitchell

unread,
Nov 30, 2022, 6:14:25 PM11/30/22
to Jansson users
I had a similar setup years ago.  various machines would broadcast json data for the others to pick up.  IIRC, I used blocking IO with threads to read the data.  That kept the overall program from blocking.
Reply all
Reply to author
Forward
0 new messages