Documentation ¶
Overview ¶
Package gojsonata provides utility functions to execute JSONata expression for JSON data transformations
Index ¶
- func AddModuleFile(filename string) error
- func AddModuleSource(key, source string) error
- func CachedModules() []string
- func CallScript(source, result string) (otto.Value, error)
- func CallScriptFile(filename, result string) (otto.Value, error)
- func RunScript(source interface{}) (otto.Value, error)
- func Transform(data, expr string) (string, error)
- type Engine
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddModuleFile ¶
AddModuleFile loads content of a js module file and add the result to cache, so later script evaluation can use this module
func AddModuleSource ¶
AddModuleSource loads source code of a js module file and add the result to cache, so later script evaluation can use this module
func CachedModules ¶
func CachedModules() []string
CachedModules returns names of js modules currently loaded in the engine
func CallScript ¶
CallScript evaluates a js script, and return value of specified result var It checks if all required modules are loaded in cache
func CallScriptFile ¶
CallScriptFile evaluates content of js or json file, and return value of specified result var the file extension must be .js or .json
Types ¶
type Engine ¶
Engine is modular vm environment
func (*Engine) LoadModule ¶
LoadModule loads source code of a js module. It recursively loads dependent modules required by the source code. All dependent modules' source code should be preloaded in jsdata, or loaded before this module. Note: this implementation is based on https://github.com/ddliu/motto/blob/master/module.go
func (*Engine) Require ¶
Require implements js 'require(name)' for modeules. It first check if the module is already in cache, then check if it is a preloaded resource in jsdata. It returns error if source code of the specified module is not found. Note: input name may contains file path info, e.g., ./js/mycode.js, but the cache key will use only the file name without suffix, i.e., mycode => value