Skip to content

Commit

Permalink
feat: add .JSON() & .JSONArray() methods to string
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe authored and moshloop committed Dec 15, 2023
1 parent 6b2354a commit 9b68dee
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
2 changes: 2 additions & 0 deletions funcs/cel_exports.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 33 additions & 3 deletions funcs/data_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/cel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ func TestCelJSON(t *testing.T) {
{nil, `[{'name': 'John'}].toJSON()`, `[{"name":"John"}]`},
{nil, `dyn({'name': 'John'}).toJSON()`, `{"name":"John"}`},
{nil, `{'name': 'John'}.toJSON()`, `{"name":"John"}`},
{nil, `toJSON({'name': 'John'})`, `{"name":"John"}`},
{nil, `1.toJSON()`, `1`},
{nil, `'{"name": "John"}'.JSON().name`, `John`},
{nil, `'{"name": "Alice", "age": 30}'.JSON().name`, `Alice`},
{nil, `'[1, 2, 3, 4, 5]'.JSONArray()[0]`, `1`},
{map[string]interface{}{"i": person}, "jq('.Address.city_name', i)", "Kathmandu"},
{map[string]interface{}{"i": person}, "toJSONPretty('\t', i)", "{\n\t\"Address\": {\n\t\t\"city_name\": \"Kathmandu\"\n\t},\n\t\"name\": \"Aditya\"\n}"},
{map[string]interface{}{"i": person}, "toJSONPretty('\t', [\"Alice\", 30])", "[\n\t\"Alice\",\n\t30\n]"},
Expand Down

0 comments on commit 9b68dee

Please sign in to comment.