modulepackage
0.4.0
Repository: https://github.com/huangjunwen/jsonlogic-go.git
Documentation: pkg.go.dev
# README
jsonlogic-go
A jsonlogic library in golang.
It is meant to be a 'stricter' version comparing to the js version: It should behave the same as the js version, if not then an error should be returned.
This means that if an expression is evaluated successful in server side using this library, then it is expected to be evaluated to the same result in client side. But the reverse direction maybe not true.
Notable restrictions
==
/!=
operations are not supported. Use strict version instead:===
/!==
- Many operations will check the minimal number of params. See doc for detail. Some examples:
{"var":[]}
is ok in js. But not ok in jsonlogic-go. ({"var":null}
or{"var":[null]}
is ok though){"===":["x"]}
is ok in js. But jsonlogic-go requires at least two params.
- Many operations will check the type of params. Some examples:
- Comparing and equality checking only accepts json primitves (
null/bool/numeric/string
)- You can still
{">":[1,"-1"]}
but not{">":[1,[]]}
- You can still
- Comparing and equality checking only accepts json primitves (
- No
NaN
/+Inf
/-Inf
:{"/":[1,0]}
getsnull
in js but got an error in this library.
Reference
- Comparing in js: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Less_than
Alternatives
Alternative jsonlogic implementation in golang you may also interested.
LICENSE
MIT
# Functions
AddOpAdd adds "+" operation to the JSONLogic instance.
AddOpAll adds "all" operation to the JSONLogic instance.
AddOpAnd adds "and" operation to the JSONLogic instance.
AddOpCat adds "cat" operation to the JSONLogic instance.
AddOpDiv adds "/" operation to the JSONLogic instance.
AddOpDoubleNegative adds "!!" operation to the JSONLogic instance.
AddOperation is equivalent to DefaultJSONLogic.AddOperation.
AddOpFilter adds "filter" operation to the JSONLogic instance.
AddOpGreaterEqual adds ">=" operation to the JSONLogic instance.
AddOpGreaterThan adds ">" operation to the JSONLogic instance.
AddOpIf adds "if"/"?:" operation to the JSONLogic instance.
AddOpIn adds "in" operation to the JSONLogic instance.
AddOpLessEqual adds "<=" operation to the JSONLogic instance.
AddOpLessThan adds "<" operation to the JSONLogic instance.
AddOpMap adds "map" operation to the JSONLogic instance.
AddOpMax adds "max" operation to the JSONLogic instance.
AddOpMerge adds "merge" operation to the JSONLogic instance.
AddOpMin adds "min" operation to the JSONLogic instance.
AddOpMinus adds "-" operation to the JSONLogic instance.
AddOpMissing adds "missing" operation to the JSONLogic instance.
AddOpMissingSome adds "missing_some" operation to the JSONLogic instance.
AddOpMod adds "%" operation to the JSONLogic instance.
AddOpMul adds "*" operation to the JSONLogic instance.
AddOpNegative adds "!" operation to the JSONLogic instance.
AddOpNone adds "none" operation to the JSONLogic instance.
AddOpOr adds "or" operation to the JSONLogic instance.
AddOpReduce adds "reduce" operation to the JSONLogic instance.
AddOpSome adds "some" operation to the JSONLogic instance.
AddOpStrictEqual adds "===" operation to the JSONLogic instance.
AddOpStrictNotEqual adds "!==" operation to the JSONLogic instance.
AddOpSubstr adds "substr" operation to the JSONLogic instance.
AddOpVar adds "var" operation to the JSONLogic instance.
Apply is equivalent to DefaultJSONLogic.Apply.
ApplyParams apply data to an array of params.
Clone is equivalent to DefaultJSONLogic.Clone.
CompareValues compares json primitives.
IsPrimitive returns true if obj is json primitive (null/bool/float64/string).
New creates a root (no parent) JSONLogic with standard operations.
NewEmpty creates a root (no parent) JSONLogic with no operation.
NewInherit creates a child JSONLogic instance.
ToBool returns the truthy of a json object.
ToNumeric converts json primitive to numeric.
ToString converts json primitive to string.
# Variables
DefaultJSONLogic is the JSONLogic instance used by package-level Apply/AddOperation.
# Type aliases
No description provided by the author
CompSymbol represents compare operator.
No description provided by the author
TestCases is a set of test cases.