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

Error when serializing sub object #8

Open
guillaumechereau opened this issue Nov 28, 2016 · 0 comments
Open

Error when serializing sub object #8

guillaumechereau opened this issue Nov 28, 2016 · 0 comments

Comments

@guillaumechereau
Copy link

I am trying to parse a json file (using json.h) and then serialize a sub object of it using json-builder, but I get some strange results.

In this simple example, my input data is:

{ "data": {"x": 10}}

And I try to serialize {"x": 10}, but instead I get:

{ "x": 10 }{ "data": { "x": 10 } }

Here is the code, compiled on linux with gcc:

#include "json-builder.h"
#include <string.h>
#include <stdio.h>

static const char *JSON = "{\"data\": {\"x\":10}}";

int main()
{
    char err[128];
    char *buf;
    json_value *value, *data;
    json_settings settings = {};
    settings.value_extra = json_builder_extra;
    value = json_parse_ex(&settings, JSON, strlen(JSON), err);
    data = value->u.object.values[0].value;
    buf = malloc(json_measure(data));
    json_serialize(buf, data);
    printf("%s\n", buf);
    free(buf);
    json_builder_free(value);
}
guillaumechereau added a commit to Stellarium/stellarium-web-engine that referenced this issue Jul 25, 2019
The previous way of serializing wasn't good because of a bug in the json
library used: json-parser/json-builder#8

Here we do the copy by iterating the object.
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

1 participant