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
307 B
ChaiScript
7 lines
307 B
ChaiScript
// object_from_json: returns Dynamic_Object with dot-access on JSON fields
|
|
var obj = object_from_json("{\"name\":\"ChaiScript\",\"version\":6,\"active\":true}")
|
|
assert_equal(obj.name, "ChaiScript")
|
|
assert_equal(obj.version, 6)
|
|
assert_equal(obj.active, true)
|
|
assert_equal(obj.get_type_name(), "JSON_Object")
|