From 0efae7db7b5870246f1e294a5fedaa69e9c90331 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 20 Feb 2024 15:40:02 +0200 Subject: Add json_map and json_set buildfile value types These expose the std::map and std::set types to buildfiles. New functions: $size() $size() $keys() Note that the $keys() function returns the list of map key as a json array. For example: m = [json_map] 2@([json] a@1 b@2) 1@([json] 1 2) s = [json_set] ([json] x@1 y@2) ([json] a@1 b@2) print ($m[2][b]) # 2 print ($s[([json] y@2 x@1)]) # true --- tests/type/json/testscript | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests/type/json') diff --git a/tests/type/json/testscript b/tests/type/json/testscript index 0e9af95..6dd6316 100644 --- a/tests/type/json/testscript +++ b/tests/type/json/testscript @@ -451,3 +451,47 @@ abc EOO } + +: json-map +: +{ + : basics + : + $* <>EOO + m = [json_map] 2@([json] a@1 b@2) 1@([json] 1 2) 0@([json] null) -1@null + print $m + for p: $m + print $first($p) $second($p) + print ($m[1]) + print $type($m[1]) + print ($m[2][b]) + EOI + -1@"" 0@"" 1@[1,2] 2@{"a":1,"b":2} + -1 "" + 0 "" + 1 [1,2] + 2 {"a":1,"b":2} + [1,2] + json + 2 + EOO +} + +: json-set +: +{ + : basics + : + $* <>EOO + s = [json_set] ([json] x@1 y@2) ([json] a@1 b@2) + print $s + for v: $s + print $type($v) $v + print ($s[([json] y@2 x@1)]) + EOI + {"a":1,"b":2} {"x":1,"y":2} + json {"a":1,"b":2} + json {"x":1,"y":2} + true + EOO +} -- cgit v1.1