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>
10 lines
242 B
ChaiScript
10 lines
242 B
ChaiScript
// object_to_map and map_to_object conversions
|
|
var m = ["a": 1, "b": "hello"]
|
|
var obj = map_to_object(m)
|
|
assert_equal(obj.a, 1)
|
|
assert_equal(obj.b, "hello")
|
|
|
|
var m2 = object_to_map(obj)
|
|
assert_equal(m2["a"], 1)
|
|
assert_equal(m2["b"], "hello")
|