saoudrizwan / DynamicJSON

Access JSON properties dynamically like JavaScript using Swift 4.2's new @dynamicMemberLookup feature

Home Page:https://twitter.com/sdrzn/status/1080340307802173440

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSON values aren't decomposed in JSON dictionary literals

WilsonGramer opened this issue · comments

Composing a dictionary literal with JSON properties results in those properties being null, instead of decomposing them into dictionaries themselves. For example, when

let foo = ["foo": 3] as JSON
let bar = ["bar": foo] as JSON

bar should equal

[
    "foo": [
        "bar": 3
    ]
] as JSON

However, bar actually equals

[
    "foo": JSON.null
] as JSON

To fix this issue, the JSON.init(_ object: Any) initializer should set self to object when object is an instance of JSON. I'll submit a PR for this later today; let me know what you think!

Thanks for pointing this out. I just pushed a fix in version 2.0.2