Skip to content

Instantly share code, notes, and snippets.

@anatooly
Created July 1, 2013 20:50
Show Gist options
  • Save anatooly/5904523 to your computer and use it in GitHub Desktop.
Save anatooly/5904523 to your computer and use it in GitHub Desktop.
// valac --thread --pkg json-glib-1.0 json.vala
using Json;
int main(string[] args) {
size_t length;
string json;
string[] std_fields = {
"param1", "param2", "param3",
"param4", "param5", "param6"
};
// Start a Generator and setup some fields for it
var gen = new Generator();
var root = new Json.Node(NodeType.OBJECT);
var object = new Json.Object();
root.set_object(object);
gen.set_root(root);
var value3 = new Json.Object();
object.set_string_member("key1", "value1");
object.set_string_member("key2", "value2");
object.set_object_member("key3", value3);
var fields = new Json.Array();
foreach(string s in std_fields) {
fields.add_string_element(s);
}
value3.set_array_member("key4", fields);
json = gen.to_data(out length);
stdout.printf(@"$json\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment