mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-04-30 19:09:26 +08:00
Add object_from_json as a non-breaking alternative to from_json that returns a Dynamic_Object instead of a Map, enabling dot-access syntax on JSON fields (e.g. obj.name instead of obj["name"]). Nested JSON objects become nested Dynamic_Objects. Also add map_to_object and object_to_map for Python-style interconversion between maps and objects. Co-authored-by: leftibot <leftibot@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
7 lines
214 B
ChaiScript
7 lines
214 B
ChaiScript
// object_from_json roundtrip through to_json
|
|
var json_str = "{\"key\":\"value\"}"
|
|
var obj = object_from_json(json_str)
|
|
var result = to_json(obj)
|
|
var obj2 = object_from_json(result)
|
|
assert_equal(obj2.key, "value")
|