Skip to content

Commit

Permalink
Handle v elements in JSON simplify (#268)
Browse files Browse the repository at this point in the history
`(v: <value>)` may be used in some cases to encode arbitrarily-typed values (a play on the `%v` verb in Go string templating).
  • Loading branch information
orlade-anz authored Jan 12, 2023
1 parent 8ea26d1 commit 59fd5bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions contrib/json.arrai
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ let rec simplify = \j
(:a): simplify(a),
(:b): b,
(:s): s,
# May be used in some cases to encode arbitrarily-typed values.
(:v): simplify(v),
(): {},
_: cond {
# Base case: j is a number.
Expand Down
11 changes: 10 additions & 1 deletion contrib/json_test.arrai
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ let (:simplify, :tuplify, :decodeSimple, :toJson, :toJsonString, ...) = //{./jso
's': (s: 'hi'),
'true': (b: true),
'false': (b: false),
}) = {'a': [1, 2], 's': 'hi', 'true': true, 'false': false},
'zero': 0,
'date': (v: (ext: 123, loc: {}, wall: 0)),
}) = {
'a': [1, 2],
's': 'hi',
'true': true,
'false': false,
'zero': 0,
'date': {'ext': 123, 'loc': {}, 'wall': 0},
},
),

tuplify: (
Expand Down

0 comments on commit 59fd5bc

Please sign in to comment.