jsonatatranslator

package
v1.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 5 Imported by: 0

README

JSONata Translator

jsonatatranslator implements the Translator plugin interface (pkg/plugin/definition/translator.go) using the JSONata expression language. Translate(ctx, artifact, payload) treats artifact as JSONata expression text, compiles it (cached by expression text, up to 500 entries), and evaluates it against payload.

It's the default translator for reqmapper's payloadTransformer step and schemaversionmediator — see CONFIG.md. Both share one instance (and its expression cache) when configured on the same handler.

Config

translator:
  id: jsonatatranslator

No config keys are read today; config is accepted only for interface consistency with other TranslatorProvider plugins.

Notes

  • Compile and evaluate errors are both wrapped with %w, so callers can still errors.As into an underlying *v206.JSONataError.
  • There's no compile-only validation entry point — a bad expression only surfaces on first Translate call, not at load time. reqmapper used to compile mappings eagerly at startup before this migration; that fail-fast behavior is gone now that execution lives behind the engine-agnostic Translator interface.
  • ctx isn't forwarded to the evaluator — jsonata-go doesn't support cancellation.

Documentation

Overview

Package jsonatatranslator implements definition.Translator using the JSONata expression language.

Index

Constants

This section is empty.

Variables

View Source
var Provider = provider{}

Provider is the exported symbol the plugin manager looks up.

Functions

func New

func New(_ context.Context, _ map[string]string) (definition.Translator, func() error, error)

New constructs a Translator. config has no recognised keys yet; accepted for interface consistency.

Types

type Translator

type Translator struct {
	// contains filtered or unexported fields
}

Translator implements definition.Translator by compiling (with caching) and evaluating JSONata expressions. The artifact passed to Translate is the raw JSONata expression text; payload is the JSON fragment to transform.

func (*Translator) Translate

func (t *Translator) Translate(_ context.Context, artifact []byte, payload []byte) ([]byte, error)

Translate compiles (with caching) the JSONata expression carried in artifact and evaluates it against payload, returning the transformed JSON bytes. ctx is accepted for interface consistency; jsonata-go does not support context cancellation, so it is not forwarded to the evaluator.

Access to the cached expression is serialized — see cachedExpr. The non-nil bindings map also makes Evaluate allocate a fresh per-call frame instead of reusing the expression's shared one.

Directories

Path Synopsis
Package main provides the plugin entry point for the JSONataTranslator plugin.
Package main provides the plugin entry point for the JSONataTranslator plugin.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL