I'm trying to write a small replacement for i3status, a small programm that comunicates with i3bar conforming this protocol. They exchange messeages via stdin and stdout.
The stream in both directions is an infinite array of json objects. The start of the stream from i3bar to i3status (which i want to replace) looks like this:
[
{"name": "some_name_1","instance": "some_inst_1","button": 1,"x": 213,"y": 35}
,{"name": "some_name_1","instance": "some_inst_2","button": 2,"x": 687,"y": 354}
,{"name": "some_name_2","instance": "some_inst","button": 1,"x": 786,"y": 637}
,{"name": "some_name_3","instance": "some_inst","button": 3,"x": 768,"y": 67}
...
This is an "array" of objects which represent clicks. The array will never close.
My question is now: What is the right way of parsing this?
Obviously I cannot use the json library because this is not a vaild json object.
,from the beginning, and then use the json library to parse the rest of the line: that is just a json object, right? (and the better way was probably posted while leaving this comment, so use that instead ;) that's why this is not an answer :) )]), meaning it cannot be infinite. I would not expect a JSON parsing library to be able to handle it via the normal means, though you might be able to invoke some of its parsing functionality if it exposes it.