Parsing Json question

Take a look at the scene section from my Json output file:

“scenes”: [ { “active”: 0, “name”: “30 after Sunset”, “id”: 20, “room”: 5 },
{ “active”: 0, “name”: “30 before sunrise”, “id”: 18, “room”: 5 },
{ “active”: 0, “name”: “All Off”, “id”: 7, “room”: 5, “state”: -1, “comment”: “” },
{ “active”: 0, “name”: “All On”, “id”: 5, “room”: 5, “state”: 4, “comment”: “Galley Accent : Transmit was ok” },
{ “active”: 0, “name”: “Debug 1”, “id”: 19, “room”: 5 },
{ “active”: 0, “name”: “Leave”, “id”: 6, “room”: 5 },
{ “active”: 0, “name”: “Tv”, “id”: 8, “room”: 5 },
{ “active”: 0, “name”: “ZC-1 B1 off”, “id”: 4, “room”: 5 },
{ “active”: 0, “name”: “ZC-1 B1 on”, “id”: 3, “room”: 5 },
{ “name”: “ZC-1 B2 off”, “id”: 10, “room”: 5, “active”: 1 },
{ “name”: “ZC-1 B2 on”, “id”: 9, “room”: 5, “active”: 0 },
{ “name”: “ZC-1 B3 off”, “id”: 13, “room”: 5, “active”: 0 },
{ “name”: “ZC-1 B3 on”, “id”: 12, “room”: 5, “active”: 1 },
{ “name”: “ZC-1 B4 off”, “id”: 17, “room”: 5, “active”: 0 },
{ “name”: “ZC-1 B4 on”, “id”: 16, “room”: 5, “active”: 1 } ]

Why does the Vera change the location of “active”?
It sure would be easier to parse if they used common rules!
Arggg!
Regards
Tim Alls

"scenes":
 [ 
{ "active": 0, "name": "30 after Sunset", "id": 20, "room": 5 }, 
{ "active": 0, "name": "30 before sunrise", "id": 18, "room": 5 }, 
{ "active": 0, "name": "All Off", "id": 7, "room": 5, "state": -1, "comment": "" }, 
{ "active": 0, "name": "All On", "id": 5, "room": 5, "state": 4, "comment": "Galley Accent : Transmit was ok" }, 
{ "active": 0, "name": "Debug 1", "id": 19, "room": 5 }, 
{ "active": 0, "name": "Leave", "id": 6, "room": 5 }, 
{ "active": 0, "name": "Tv", "id": 8, "room": 5 }, 
{ "active": 0, "name": "ZC-1 B1 off", "id": 4, "room": 5 }, 
{ "active": 0, "name": "ZC-1 B1 on", "id": 3, "room": 5 }, 
{ "name": "ZC-1 B2 off", "id": 10, "room": 5, "active": 1 }, 
{ "name": "ZC-1 B2 on", "id": 9, "room": 5, "active": 0 }, 
{ "name": "ZC-1 B3 off", "id": 13, "room": 5, "active": 0 }, 
{ "name": "ZC-1 B3 on", "id": 12, "room": 5, "active": 1 }, 
{ "name": "ZC-1 B4 off", "id": 17, "room": 5, "active": 0 }, 
{ "name": "ZC-1 B4 on", "id": 16, "room": 5, "active": 1 }
 ]

Does that make more sense Tim?

JSON, XML, HTML, etc all use enclosing-delimiters. In this case “scenes” has 15 data items surrounded by [] and separated by commas. The “active” data field has 4 data items surrounded by {} and separated by commas.

My simple parser takes delimiters as a calling argument and returns an array of strings that were separated by commas. Iterate into each array item the same way and eventually you get to real data which is within the context of the arrays that enclose it. Easy!

Hope that helps?
bob

Hi TimAlls,

[quote=“TimAlls, post:1, topic:168325”]Why does the Vera change the location of “active”?
It sure would be easier to parse if they used common rules![/quote]

It’s weird, but perfectly allowed. JSON objects (enclosed in braces) are by definition unordered (source: section 1 of http://www.ietf.org/rfc/rfc4627.txt). That means that the order that Vera serializes them in is irrelevant, and that any parser has to accept the members no matter what order they come in.

Are you writing your own JSON parser? You are working in a language that doesn’t already have one (see http://www.json.org/ for a list)?

Oh just let me bitch! Ha
Of course I can do it…just takes more time …and that, I just don’t have enough of!
FlyBoyBob, I snipped it out of my file to show, so the delimiters are all correct in my original code. It just doesn’t make sense to switch things around when the JSON output is software generated. Just a little frustrated today. But on a good note I just posted another piece of code…[url=http://forum.micasaverde.com/index.php?topic=6547.0]http://forum.micasaverde.com/index.php?topic=6547.0[/url]
FlyBoyBob, you must try it and give me some feedback. It was you that got me started at this! (and No, no parsing tools, I am doing it from scratch)

Regards
Tim