Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array with objects support #202

Closed
Typnix opened this issue Oct 15, 2015 · 2 comments
Closed

Array with objects support #202

Typnix opened this issue Oct 15, 2015 · 2 comments

Comments

@Typnix
Copy link

Typnix commented Oct 15, 2015

Hi,

Is it possible to add support for array of objects? Just like the following output:

myOtherArray = [
{
"first" : "John",
"last" : "Smith"
},
{
"first" : "Jane",
"last" : "Doe"
}
];

@pilkch
Copy link

pilkch commented Nov 16, 2015

I'm no expert but I think it can already do this?
// Create a new array to add our properties to
json_object* new_array = json_object_new_array();
json_object_object_add(current, type, new_array);

for each item in the array: {
       for each property of each item: {
            // Add a new element so that we can add a pair for the name and value
            json_object* str_value = json_object_new_string(iter->second.c_str());
            json_object* pair_object = json_object_new_object();
            json_object_object_add(pair_object, iter->first.c_str(), str_value);
       }

       // Add the pair to the array
       json_object_array_add(new_array, pair_object);
}

@rgerhards
Copy link
Contributor

yup, that's possible

@hawicz hawicz closed this as completed Nov 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants