Skip to content

gorenje/erlang-red-jsonata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Erlang Parser for JSONata

Erlang CI

Erlang parser implementation for the JSONata transform language.

JSONata plays a central role in Node-RED - the low-code visual flow-based programming environment.

This is an implementation for the Erlang-RED codebase. Erlang-RED is the low-code visual flow-based programming environment inspired by Node-RED!

What is flow based programming? A programming paradigm focussed on message passing between independent computational units.

Architecture

This library transforms JSONata stanzas into valid Erlang code which are intended to be executed in the presence of a Msg map.

For example:

$$.payload.fuba.dad + 1 + 2 + $$.payload.name.name + 3 + 4 * 6

becomes:

fun (Msg) ->
    maps:get(<<"dad">>, maps:get(<<"fuba">>, maps:get(<<"payload">>, Msg))) + 1 + 2 +
         maps:get(<<"name">>, maps:get(<<""name">>, maps:get(<<"payload">>, Msg))) + 3 + 4 * 6
end.

Breaking change: Keys are no longer atoms, they have become binaries.

JSONata Support

At the time of writing, this library supports a minimum set of functionality of the original JSONata language. Of all the functions plus the Node-RED extensions, this supports:

Function Comment
$append Supported
$base64encode Supported
$base64decode Supported
$count Supported
$distinct Supported
$formatBase Supported
$join Supported
$keys Supported
$length Supported
$map Supported
$match Supported
$millis Supported - including the requirement that multiple calls produce the same value
$not Supported
$now Supported - including passing value, e.g., $now($millis())
$pad Supported
$random Supported
$replace Supported - initial support for regular expressions
$split Supported
$string Supported
$trim Supported
$type Supported
$substring Supported
$sum Supported
--- ---
$erl (Erlang-RED only) Erlang operator for evaluating Erlang stanzas. Good for tuples and improper lists and atoms.
$pauseMillis (Erlang-RED only) Pause this many milli seconds
$privdir (Erlang-Red only) Retrieve the location of the /priv directory
$toString (Erlang-RED only) Convert anything and everything to a binary
$toList (Erlang-RED only) Convert anything and everything to a list
$flatten (Erlang-RED only) Flatten arrays into single arrays lists:flatten/1

Functions are defined in two places in the parser or in the evaluator.

There is no particular timeline to extend that list, functionality is being added as needed by the flow tests the define the current behaviour of existing Node-RED nodes.

Build

$ rebar3 compile

Test

$ rebar3 eunit

Coffee Time

Buy Me A Coffee

About

Erlang parser for JSONata transformation language

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published