Skip to content

Add JSONata template evaluation via gnata#152

Open
Copilot wants to merge 2 commits intomainfrom
copilot/add-jsonata-function
Open

Add JSONata template evaluation via gnata#152
Copilot wants to merge 2 commits intomainfrom
copilot/add-jsonata-function

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 28, 2026

Adds JSONata 2.x expression evaluation as a first-class option on the Template struct, backed by github.com/recolabs/gnata. Custom gomplate functions are exposed in the JSONata environment; gnata's native built-ins take precedence on any name collision.

Template struct

  • New Jsonata string field (yaml:"jsonata", json:"jsonata")
  • RunTemplateContext evaluates the Jsonata field after the existing CEL path
  • IsEmpty, CacheKey, String, ShortString updated accordingly

jsonata.go — new file

  • gnataBuiltinFunctions set guards against overriding native JSONata semantics
  • getJSONataCustomFuncs() exposes gomplate-specific functions as gnata.CustomFunc wrappers, skipping any name in the builtin set:
    • Crypto: $sha1 / $sha224 / $sha256 / $sha384 / $sha512 / $sha512_224 / $sha512_256
    • Data: $toJSON / $fromJSON / $toYAML / $fromYAML
    • Query: $jq / $jmespath / $jsonpath
    • Regexp: $regexpFind / $regexpFindAll / $regexpMatch / $regexpReplace / $regexpReplaceLiteral / $regexpSplit
    • Format: $f — go-template format string (mirrors the CEL f() function)
  • Shared customJSONataEnv initialized once at startup; expressions are cached per-expression string

Usage

out, err := gomplate.RunTemplate(env, gomplate.Template{
    Jsonata: `Account.Orders.$sum(Product.(Price * Quantity))`,
})

// Custom functions available in expressions:
out, err = gomplate.RunTemplate(nil, gomplate.Template{
    Jsonata: `$sha256("hello")`,
})
// → "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"

Tests (tests/jsonata_test.go)

New test suite mirroring the existing CEL tests: basic path/arithmetic, built-in string/array/math/object functions, all custom gomplate functions, and a precedence test confirming gnata native functions cannot be shadowed.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add JSONata function with custom CEL expressions support Add JSONata template evaluation via gnata Mar 28, 2026
Copilot AI requested a review from moshloop March 28, 2026 17:30
@moshloop moshloop force-pushed the copilot/add-jsonata-function branch from be082e8 to ba89ebb Compare March 30, 2026 10:50
@moshloop moshloop marked this pull request as ready for review March 30, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants