JSON manipulation functions for Predicator expressions.
Provides SCXML-compatible JSON functions for serializing and parsing data.
Available Functions
JSON.stringify(value)- Converts a value to a JSON stringJSON.parse(string)- Parses a JSON string into a value
Examples
iex> {:ok, result} = Predicator.evaluate("JSON.stringify(user)",
...> %{"user" => %{"name" => "John", "age" => 30}},
...> providers: [Predicator.Functions.JSONFunctions])
iex> result
~s({"age":30,"name":"John"})
iex> {:ok, result} = Predicator.evaluate("JSON.parse(data)",
...> %{"data" => ~s({"status":"ok"})},
...> providers: [Predicator.Functions.JSONFunctions])
iex> result
%{"status" => "ok"}
Summary
Functions
Parses a JSON string into a value.
Converts a value to a JSON string.
Returns all JSON functions as a Predicator.FunctionProvider map.
Types
@type function_result() :: {:ok, Predicator.Types.value()} | {:error, binary()}
Functions
@spec call_parse([Predicator.Types.value()], Predicator.Context.t()) :: function_result()
Parses a JSON string into a value.
@spec call_stringify([Predicator.Types.value()], Predicator.Context.t()) :: function_result()
Converts a value to a JSON string.
@spec functions() :: %{ required(Predicator.FunctionProvider.name()) => Predicator.FunctionProvider.entry() }
Returns all JSON functions as a Predicator.FunctionProvider map.