Skip to content

Assigning values to a json structur #2

@gonwalf

Description

@gonwalf

Hi!

I'm testing rl_json right now. Parsing JSON strings and getting values works fine. But when I try to set values, I'm having some difficulties. Consider the following code:

package require rl_json
set jsonstr {
    {
        "foo": "Foo",
        "baz": "Baz"
    }
}

json set jsonstr bar Bar FooBar test {"x"}
puts [json normalize $jsonstr]

json set jsonstr bar Bar FooBar test2 {"y"}
puts [json normalize $jsonstr]

json set jsonstr bar Bar FooBar test3 {"z"}
puts [json normalize $jsonstr]

I'd expect the following end result:

{"foo":"Foo","baz":"Baz","bar":{"Bar":{"FooBar":{"test":"x","test2":"y","test3":"z"}}}}

Instead I get this result:

{"foo":"Foo","baz":"Baz","bar":{"Bar":{"FooBar":{"test":"x","test2":null,"bar":{"Bar":{"FooBar":{"test3":"y"}}},"test3":null}}}}

Another problem I have is changing a value, e.g:

package require rl_json

set jsonstr {
    {
        "foo": "Foo",
        "baz": "Baz"
    }
}

json set jsonstr foo {"Bar"}
puts [json normalize $jsonstr]

exits with the error message

missing value to go with key

The speed of the implementation is very impressive. If setting values would work, JSON would really feel like a native datatype of TCL.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions