Skip to content

Question about flatten and unflatten #1989

@dota17

Description

@dota17
json j  = R"({
        "bad": {
            "0": "one",
            "1": "two",
            "2": "three"
        },
        "foo": "bar"
    })"_json;
json j_flatten = {
        {"/bad/0", "one"},
       {"/bad/1", "two"},
       {"/bad/2", "three"},
       {"/foo",   "bar"}
};

I had tested that j.flatten() == j_flatten is true and j_flatten.unflatten() == j is false.
From the source code, it might just look at the first pointer - if there is a "0" reference_token, it will start a new array. And the behavior will cause that under the following cases, we cannot use unflatten():

    json j_flatten =
            {
                    {"/bad/0", "one"},
                    {"/bad/1", "two"},
                    {"/bad/t", "three"},
                    {"/foo",   "bar"}
            };

when calling unflatten(), [json.exception.parse_error.109] parse error: array index 't' is not a number will be raised.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: questionstate: help neededthe issue needs help to proceedstate: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updated

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions