Help creating json

51 views
Skip to first unread message

saptah

unread,
Feb 19, 2012, 4:20:58 PM2/19/12
to Jansson users
Hi Guys, I'm newBIE here.
Let me ask one question :)

I'm trying to construct a JSON like this:

{
"type": "some_string",
"device": {
............
............
............
............
"stations": [...]
},
}


1.- I already have the "......" block, I loaded using json_load_file()
2.- I got the array after "stations". loaded with json_load_file() too
3.- I've tried some thinks, but, the next think what I think should
work, but I doesn't:

json_final = json_pack( "{s:s{s:o}}",
"type", "sisco",
"device", json_object
);


¿Can you help me to understand this library? BTW, great library, looks
very neat, but I'm very very new to this.

Petri Lehtinen

unread,
Feb 20, 2012, 1:57:33 PM2/20/12
to jansso...@googlegroups.com

Try:

final = json_pack("{s:s, s:o, s:o}",
"type", "some_string",
"device": device_object,
"stations": stations_array);

So you're just packing a simple object whose members are mostly other
JSON values that can be included with the "o" character.

Petri

vicent roca daniel

unread,
Feb 20, 2012, 4:02:04 PM2/20/12
to jansso...@googlegroups.com
Hi Petri,

That worked beautifully, Thanks!!


Reply all
Reply to author
Forward
0 new messages