Code Monkey home page Code Monkey logo

jsonlogic's People

Contributors

alexjunioravila avatar craigpangea avatar darrendao avatar diegoholiveira avatar evgenus avatar fifthaxe avatar florianruen avatar jinjaghost avatar joaoandre avatar julianogalgaro avatar kavindu-dodan avatar lucianomagrao avatar okhowang avatar reb-felipe avatar rymmugygr avatar sah4ez avatar tlugger avatar vivekagrawal2810 avatar yy-dev7 avatar zachcheh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsonlogic's Issues

Less than operator returns true with strings instead of false

To Reproduce

  1. Run the following code
package main

import (
	"bytes"
	"fmt"
	"strings"

	"github.com/diegoholiveira/jsonlogic/v3"
)

func main() {
	logic := strings.NewReader(`{"<": ["abc", 3]}`)
	data := strings.NewReader(`{}`)

	var result bytes.Buffer

	jsonlogic.Apply(logic, data, &result)

	fmt.Println(result.String())
}

Expected
false

"abc" is not less than 3.
Using the same logic / data here https://jsonlogic.com/play.html will return the expected result.

Screenshot 2022-02-25 at 12 31 12

Actual
true

invalid: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2

Step-by-step

  1. I took the first example from the readme.
  2. Created a module: go mod init myNewProject
  3. Edited my go.mod
module myNewProject

go 1.13

require (
        github.com/diegoholiveira/jsonlogic/v2 v2.5.2
        github.com/mitchellh/copystructure v1.0.0 // indirect
)
  1. Then: go get
require github.com/diegoholiveira/jsonlogic: version "v2.5.2" invalid: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2

Possible solutions

  • change your module name in go.mod to github.com/diegoholiveira/jsonlogic/v2
    • But you have to delete tag that don't begin with v
  • or change to /v3 and create a new v3.0.0 tag.

[PANIC RECOVER] interface conversion: interface {} is []interface {}, not map[string]interface {}

func TestGetVarArray(t *testing.T){
	rule := strings.NewReader(`{
          "and": [
            {
              "==": [
                { "var" : "tempNumbers.0"},
               "123-456"
              ]
            },
            {
              "==": [
                { "var" : "tempNumbers.1"},
                "234-567"
              ]
            }
          ]
        }`)

	data := strings.NewReader(`{
          "tempNumbers": [
            "123-456",
            "234-567",
            "345-678"
          ]
        }`)

	var result bytes.Buffer

	jsonlogic.Apply(rule, data, &result)

	fmt.Println(result.String())

}

this is the stack trace :

github.com/diegoholiveira/jsonlogic.getVar(0x74af80, 0xc000182d60, 0x75c0e0, 0xc000185620, 0x100000000754da0, 0xffffffffffffffff)
/home/nicholas/Desktop/clone/golang-body-parser/src/vendor/github.com/diegoholiveira/jsonlogic/vars.go:91 +0x725
github.com/diegoholiveira/jsonlogic.operation(0xc000025f36, 0x3, 0x74af80, 0xc000182d60, 0x75c0e0, 0xc000185620, 0x400, 0x7f0e4ca68f00)
/home/nicholas/Desktop/clone/golang-body-parser/src/vendor/github.com/diegoholiveira/jsonlogic/jsonlogic.go:540 +0x1105
github.com/diegoholiveira/jsonlogic.apply(0x75c0e0, 0xc000185590, 0x75c0e0, 0xc000185620, 0x194, 0x4007f0e73595768)
/home/nicholas/Desktop/clone/golang-body-parser/src/vendor/github.com/diegoholiveira/jsonlogic/jsonlogic.go:708 +0x1dc
github.com/diegoholiveira/jsonlogic.parseValues(0x7465e0, 0xc00019ac20, 0x75c0e0, 0xc000185620, 0x0, 0x0)
/home/nicholas/Desktop/clone/golang-body-parser/src/vendor/github.com/diegoholiveira/jsonlogic/jsonlogic.go:674 +0x2ac
github.com/diegoholiveira/jsonlogic.apply(0x75c0e0, 0xc000185560, 0x75c0e0, 0xc000185620, 0xc000053d90, 0x30000000054128a)
/home/nicholas/Desktop/clone/golang-body-parser/src/vendor/github.com/diegoholiveira/jsonlogic/jsonlogic.go:708 +0x196
github.com/diegoholiveira/jsonlogic.parseValues(0x7465e0, 0xc00019aca0, 0x75c0e0, 0xc000185620, 0x0, 0xc000132660)
/home/nicholas/Desktop/clone/golang-body-parser/src/vendor/github.com/diegoholiveira/jsonlogic/jsonlogic.go:674 +0x2ac
github.com/diegoholiveira/jsonlogic.apply(0x75c0e0, 0xc000185530, 0x75c0e0, 0xc000185620, 0x0, 0x8d7308)
/home/nicholas/Desktop/clone/golang-body-parser/src/vendor/github.com/diegoholiveira/jsonlogic/jsonlogic.go:708 +0x196
github.com/diegoholiveira/jsonlogic.Apply(0x827320, 0xc00019abc0, 0x827320, 0xc00019abe0, 0x826c20, 0xc000185500, 0x2202e31c0000000f, 0x6071bd75)
/home/nicholas/Desktop/clone/golang-body-parser/src/vendor/github.com/diegoholiveira/jsonlogic/jsonlogic.go:736 +0x1ec
github.com/nicholasanthonys/Golang-Body-Parser/test.TestGetVarArray(0xc000001b00)
/home/nicholas/Desktop/clone/golang-body-parser/src/test/clogic_test.go:169 +0xee
testing.tRunner(0xc000001b00, 0x7d5518)
/home/nicholas/go1.15.5/src/testing/testing.go:1123 +0xef
created by testing.(*T).Run
/home/nicholas/go1.15.5/src/testing/testing.go:1168 +0x2b3

Can you help me with this ?

Error if var is missing from data

Hello,

I seem to hit a case where the library is returning an error when a property, that is in the "logic" but not in the "data". Below is an example program to reproduce the issue.

package main

import (
	"bytes"
	"fmt"
	"os"
	"strings"

	"github.com/diegoholiveira/jsonlogic"
)

func main() {
	logic := strings.NewReader(`{"logic":{"and":[{"!":{"var":"var_not_in_data"}}]}}`)
	data := strings.NewReader(`{"some_key": "value"}`)

	var result bytes.Buffer
	err := jsonlogic.Apply(logic, data, &result)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	fmt.Println(result.String())
}

And here's the output:

interface conversion: interface {} is nil, not []interface {}

Process finished with exit code 1

If I add the var_not_in_data to the data object it evaluates the expression correctly.

Edit Note: It used to panic with version 2, it just returns the error now with v3

Apply issue in go client

rule = {"and":[{"in":[{"var":"flow"},["BRAND"]]},{"or":[{"if":[{"missing":["gender"]},true,false]},{"some":[{"var":"gender"},{"==":[{"var":null},"men"]}]}]}]}

data= {"category":["sneakers"],"flow":"BRAND","gender":["men"],"market":"US"}

err = jsonlogic.Apply(bytes.NewReader(rule), bytes.NewReader(data), &resultBuffer)

getting error in this case
interface conversion: interface {} is map[string]interface {}, not string

but this case pass in playground/ javascript client

Issue with map operation

Hey @diegoholiveira

I'm having an issue when using map operation. Basically I'm trying to iterate over an array of arrays, and then using the in operation to evaluate for every given array if the passed argument is present in each one. My rule looks like this:

{
  "map": [
    {
      "var": "listOfLists"
    },
    {
      "in": [
        "item_a",
        {
          "var": ""
        }
      ]
    }
  ]
}

And the input data:

{
  "listOfLists": [
    ["item_a", "item_b", "item_c"],
    ["item_b", "item_c"],
    ["item_a", "item_c"]
  ]
}

So basically I expect to get an array of booleans as output, that informs me for every list if item_a was present:

[
    true,
    false,
    true
]

But for some reason, this is what I'm getting:

[
    true,
    true
]

It looks like it's ignoring false values, showing only the true ones. For the record, I ran the test in the JsonLogic site and I get the result I was expecting, so I think It could be an issue with the map implementation.
Thanks!

max/min logic is incorrect

Max starts with "SmallestNonzeroFloat64" which is the smallest positive, non-zero value. So max:[0,0], max:[-1,0], max:[-3,-2] and etc. will all get incorrect answer. Also, min is correctly start with maximum value but min:[] return very large number make no sense. It should return null or error *spec in jsonlogic website return null for empty or if it contains not-numeric-castable.
So I think you should start with first found number. Then compare following number with the first one, not some made-up value. Return null for not-numeric-castable/empty input if want to follow jsonlogic.

validateJsonLogic not exported

Hi. I need validateJsonLogic in my code because I decode a bunch of rules from a big JSON structure. And I want to check them when they are already interface{}.

Please export it

Support for object return types

A rule map containing more than 1 key should count as a primitive value and be returned by calling Apply. However, this is not currently the case in this package. Instead, any instance of a map parsed through recursive apply calls will continue to recurse until a primitive value is parsed and returned. An example of this case:

Rule:

{"if":[ 
	{"==":[{"var":"foo"},"bar"]},{"foo":"is_bar","path":"foo_is_bar"},
	{"foo":"not_bar","path":"default_object"}
]}

Data:

{"foo": "bar"}

The expected return value here is the full object {"foo":"is_bar","path":"foo_is_bar"} which is the case in the jsonlogic playground: https://jsonlogic.com/play.html

However, this currently is parsed to a boolean value true

Solving vars with the current value changes the behavior

In the playground (https://jsonlogic.com/play.html) and in version < 3.5.1 the following rule

{
      "some": [
        {"var": "A"},
        {"!=": [
          {"var": ".B"},
          {"var": "B"}
        ]}
      ]
}

when applied to

{"A":[{"B":1}], "B":2}

returns true.

However, since this commit 0926afe, the return value is false.

Is it a desired change? If so, how the previous functionality (of comparing the value with the value from external scope) can be achieved.

Absence of boolean equality check

Have:

func equals(a, b interface{}) bool {
	if isNumber(a) {
		return toNumber(a) == toNumber(b)
	}

	return toString(a) == toString(b)
}

Need:

func equals(a, b interface{}) bool {
	if isNumber(a) {
		return toNumber(a) == toNumber(b)
	}
        if isBool(a) {
                return isTrue(a) == isTrue(b)
         }
	return toString(a) == toString(b)
}

Else:
panic: interface conversion: interface {} is bool, not string

0 divided by any number returning denominator instead of 0

Here is the sample program to reproduce

package main

import (
	"bytes"
	"fmt"
	"strings"
	"github.com/diegoholiveira/jsonlogic"
)

func main() {
	rule := `{"/":[0,10]}`
	logic := strings.NewReader(rule)
	data := strings.NewReader(`{}`)
	var result bytes.Buffer

	jsonlogic.Apply(logic, data, &result)

	fmt.Println(result.String())

}

ApplyInterface does not support int number values

func main() {
	rule := map[string]interface{}{
		"==": []interface{}{
			map[string]interface{}{
				"var": "impact_levels",
			},
			1,
		},
	}

	data := map[string]interface{}{
		"impact_levels": 1,
	}

	output, err := jsonlogic.ApplyInterface(rule, data)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(output.(bool))
}

this returns an error, the reason seems to be that isNumber is checking for reflect.Float64, and therefor the int is assumed to be a string.

get the jsonlogic evaluated back from the method that apply

Hey @diegoholiveira,

I'm using this library to apply a jsonlogic built from my UI (using https://react-querybuilder.js.org), but for my use case, I need to help users to "debug" if the response is false

To achieve this, my idea is to print to the user, the logic applied, but I want the vars replaced directly. To be clear, instead of

{
  "and":[
    { "==":[{ "var":"VariableA" }, true] },
    { "==":[{ "var":"VariableB" }, true] },
    { ">=":[{ "var":"VariableC" }, 17179869184] },
    { "==":[{ "var":"VariableD" }, "0"] },
    { "<":[{ "var":"VariableE" }, 20] }
  ]
}

I need

{
  "and":[
    { "==":[false, true] },
    { "==":[true, true] },
    { ">=":[34359738368, 17179869184] },
    { "==":[12, "0"] },
    { "<":[14, 20] }
  ]
}

I haven't seen any function that can achieve this (only solveVars and getVar)
There is any way to get this result ?

Kindly

Override custom operator not working as expected

Hello,

I am trying to override == and all operator for my implementation. To do so, my code looks like this:

jsonlogic.AddOperator("==", util.EqualsOperator)
jsonlogic.AddOperator("all", util.AllOperator)

And then I have implementation for both the methods above that look like this:

func EqualsOperator(values, data interface{}) interface{} {
//implentation goes here
}

func AllOperator(values, data interface{}) interface{} {
//implentation goes here
}

My filter looks like this:

          {
                "and": [
                    {
                        "==": [
                            {
                                "var": "deploymentt.id"
                            },
                            "test123"
                        ]
                    },
                    {
                        "all": [
                            {
                                "var": "values"
                            },
                            [               
                              "value 1",
                              "value 2"
                            ]
                        ]
                    }
                ]
            }

I am facing a weird issue. When I run my code against this filter and sample data that should match this condition, my breakpoint for EqualsOperator hits and my override of the jsonLogic operator works. But my override of AllOperator does not work, the breakpoint never hits and it used the default jsonLogic implementation.

Can you help?

Issue while running a basic example

I used go get to install and here is the error that I got while running a basic example:

cannot use logic (type interface {}) as type io.Reader in argument to jsonlogic.Apply:
interface {} does not implement io.Reader (missing Read method)
[go]
cannot use data (type interface {}) as type io.Reader in argument to jsonlogic.Apply:
interface {} does not implement io.Reader (missing Read method)

Should substr called with a negative argument greater than the string length be an error?

In the example here, https://jsonlogic.com/operations#substr, a negative number greater than the string length is no problem. The entire string is simply returned:

{"substr": ["jsonlogic", -10]} // "jsonlogic"

However, In this minimal example, I get an error and a empty output`:

	var result bytes.Buffer
	data := strings.NewReader(`{}`)
	logic := strings.NewReader(`
	{"substr": ["jsonlogic", -10]}`)
	err := jsonlogic.Apply(logic, data, &result)
	if err != nil {
		log.Printf("err: %s", err.Error())	// err: runtime error: slice bounds out of range [-1:]
	}

	log.Printf("got result: %s", result.String()) // got result: 

I believe this is an error... So I'm looking at a fix.

Invalid evaluation

Hi contributors & users,

I am facing a bug with the following data & logic :

x Data :
{} or whatever data without a matching var
x Logic :
{"and":[{"<":[{"var":"foo"},"bar"]}]}
x Evaluation : true

You can play with the bug here : https://play.golang.org/p/1fBwpHNhxKk

What's funny is that if you change the greater for a lower, evaluation becomes falsy. In both case it should be false (as verified on jsonlogic.com playground) since there is no matching var in the data.

Thanks

Accessing data using var path inside an array

Hey, not sure if this is best place to post this question, as I don't think it is a problem with the golang jsonlogic as I am noticing the same behavior in go as I do in the play.html page on jsonlogic, but I'm trying to figure out how I can compare array values against data outside of the array

I know that var inside of an array is relative, so { "var": "id" } appears to work, but is there any way I could check that against data outside of the array like the subject.id. If var inside an array is only relative, is the only solution to add a custom operator like absolute_var, if yes, if there any online examples where I could understand how to write an operator like that in golang

Rule: {"some": [{ "var": "attributes.parents" }, {"==": [{ "var": "id" }, { "var": "subject.id" }]}]}

Data: { "subject": { "id": "hugh", }, "attributes": { "parents": [ { "id": "ryan" }, { "id": "hugh" }, ] } }

Wrong result when comparing number and string

package main

import (
	"bytes"
	"fmt"
	"strings"

	"github.com/diegoholiveira/jsonlogic/v3"
)

func main() {
	logic := strings.NewReader(`{"<": ["9", 10]}`)
	data := strings.NewReader(`{}`)

	var result bytes.Buffer

	jsonlogic.Apply(logic, data, &result)

	fmt.Println(result.String())
}

expect true
but got false

get the variable that causes a false output on jsonlogic evaluation

Hey @diegoholiveira

I'm using JsonLogic in Go backend, with sometimes complex logics (lot of sums, conditional ...)
And in order to help my end users to debug in case of false result, I'm asking if there is a way to output the variable that cause the false output

For example, output just need to be a string with variable name

{
  "and":[
    { "==":[{ "var":"VariableA" }, true] },
    { ">=":[{ "var":"VariableC" }, 17179869184] },
  ]
}

If VariableA = false and VariableC = 17179869184
The jsonlogic.Apply() output can be result, variable, err := jsonlogic.Apply()
With variable = "VariableA" (or maybe an array in case of multiple var, or maybe only the first that cause false result)

Do you think, this kind of behavior can be achieve, or because of the operation of jsonlogic which works with json, this will not be possible?

If yes, if you have some tips, maybe I can achieve this, and make another PR !

panic on interface conversion

reproduce

logic = {"==":[{"var":"test"},true]}
data = {}

stack trace

panic: interface conversion: interface {} is bool, not string [recovered]
	panic: interface conversion: interface {} is bool, not string

goroutine 6 [running]:
testing.tRunner.func1.1(0x54d6e0, 0xc000100420)
	/home/liangliangdai/.asdf/installs/golang/1.14/go/src/testing/testing.go:941 +0x3d0
testing.tRunner.func1(0xc000132120)
	/home/liangliangdai/.asdf/installs/golang/1.14/go/src/testing/testing.go:944 +0x3f9
panic(0x54d6e0, 0xc000100420)
	/home/liangliangdai/.asdf/installs/golang/1.14/go/src/runtime/panic.go:967 +0x15d
github.com/diegoholiveira/jsonlogic.toString(0x5404a0, 0x683ee1, 0x0, 0x0)
	/home/liangliangdai/.asdf/installs/golang/1.16/go/pkg/mod/github.com/diegoholiveira/[email protected]+incompatible/helpers.go:74 +0x108
github.com/diegoholiveira/jsonlogic.equals(0x0, 0x0, 0x5404a0, 0x683ee1, 0xc00000c120)
	/home/liangliangdai/.asdf/installs/golang/1.16/go/pkg/mod/github.com/diegoholiveira/[email protected]+incompatible/comp.go:34 +0xbd
github.com/diegoholiveira/jsonlogic.operation(0xc00001c2e8, 0x2, 0x53ea80, 0xc00000c140, 0x54c500, 0xc0001003c0, 0xc000068530, 0x53a400)
	/home/liangliangdai/.asdf/installs/golang/1.16/go/pkg/mod/github.com/diegoholiveira/[email protected]+incompatible/jsonlogic.go:658 +0xa70
github.com/diegoholiveira/jsonlogic.apply(0x54c500, 0xc000100360, 0x54c500, 0xc0001003c0, 0xc000068500, 0x0)
	/home/liangliangdai/.asdf/installs/golang/1.16/go/pkg/mod/github.com/diegoholiveira/[email protected]+incompatible/jsonlogic.go:708 +0x1b5
github.com/diegoholiveira/jsonlogic.ApplyRaw(0xc000016480, 0x1d, 0x20, 0xc00001c2d8, 0x2, 0x8, 0x685ae0, 0x0, 0x1, 0xc000052748, ...)
	/home/liangliangdai/.asdf/installs/golang/1.16/go/pkg/mod/github.com/diegoholiveira/[email protected]+incompatible/jsonlogic.go:761 +0x23e
study_go2/jsonlogic.TestUsage(0xc000132120)
	/home/liangliangdai/IdeaProjects/study_go2/jsonlogic/jsonlogic_test.go:13 +0xb3
testing.tRunner(0xc000132120, 0x581c90)
	/home/liangliangdai/.asdf/installs/golang/1.14/go/src/testing/testing.go:992 +0xdc
created by testing.(*T).Run
	/home/liangliangdai/.asdf/installs/golang/1.14/go/src/testing/testing.go:1043 +0x357

Process finished with the exit code 1

others

it works when modify true to "true"

image

but result different with playground, which is correct ?

image

seems no judgement for bool here

func toString(value interface{}) string {

failing to check array items by index (from an empty array)

First of all, that's a great lib, thank you all for your hard work on this!

When we try to access an specific condition in an empty array, we get index out of range.
How can we check if the array is not empty before accessing their items?

Quick playground example

logic := strings.NewReader(`{"if":[ false, {"var":"values.0.categories"}, "else" ]}`)
data := strings.NewReader(`{ "values": [] }`)

var result bytes.Buffer
if err := jsonlogic.Apply(logic, data, &result); err != nil {
    fmt.Printf("failed, %v", err)
}

fmt.Println(result.String())

In the example above, even forcing the false in the if condition, it's still evaluating the true part, causing the index out of range.
Shouldn't return the "else" value , even returning the error?
This is what the JSON Logic playground returns:

image

Is there any other way to get the value of a property from an array's item (like categories from the first position in my example)?

Thank you

all Operator not giving correct results

Hi
I am trying to run the following kind of rule
rule
{ "all": [ { "var": "" }, { "in": [ {"var": "P1"} , ["A","B"]] } ] }
for the following JSON data:
[ { "P1": "A", "P2": "a" }, { "P1": "B", "P2": "b" } ]

But the Apply function call gives me false which is incorrect evaluation.

README improvement

"Limitations" part has no comments in code that shows where exactly improper values are used.

filter body returns error when used with array-form var

Using the full {"var": [...]} syntax instead of the syntax sugar {"var": "..."} causes an error when present in a filter body. As an example, the following rule (adapted from the test suite) will fail:

	{
		"filter": [
			{"var": ["people"]},
			{"==": [
				{"var": [".age"]},
				{"min": {"map": [
					{"var": ["people"]},
					{"var": [".age"]}
				]}}
			]}
		]
	}

with the data:

	{
		"people": [
			{"age":18, "name":"John"},
			{"age":20, "name":"Luke"},
			{"age":18, "name":"Mark"}
		]
	}

I believe the cause is this line: https://github.com/diegoholiveira/jsonlogic/blob/master/vars.go#L15

panic: interface conversion error when map have only number in string key

Sample code to reproduce


import (
	"bytes"
	"fmt"
	"strings"

	"github.com/diegoholiveira/jsonlogic"
)

func main() {

	logic := strings.NewReader(`{"and":[{">":[{"*":[{"/":[{"var":"tradeItems.43443.quantity.REJECTED"},{"var":"tradeItems.43443.quantity.RECEIVED"}]},100]},0.1]}]}`)
	data := strings.NewReader(`{"tradeItems":{"43443":{"lineItemNo":1,"itemName":"Item16","SKUCode":"43443","HSNCode":"45455","quantity":{"ACCEPTED":4500,"APPROVED":0,"DESTRUCTED":0,"INTRANSIT":4500,"INVOICED":4500,"INVOICED_REMAINING":0,"INVOICE_APPROVED":0,"INVOICE_PAID":0,"INVOICE_REJECTED":0,"ORDERED":4500,"QC":4500,"QC_REMAINING":0,"READY_TO_SHIP":4500,"READY_TO_SHIP_REMAINING":0,"RECEIVED":4500,"REJECTED":0,"REQUESTED":0,"REQUESTED_REMAINING":0,"SCRAPPED":0},"supplier":{"orgId":"DESU1","orgName":"Supplier Org1","emailId":"","vendorCode":"","address":"Juhu Road","departmentId":""},"receiver":{"orgId":"DEOW1","orgName":"Buyer","emailId":"","vendorCode":"","address":"T-68-1","departmentId":""},"deliverBy":"2020-04-30T18:29:59Z","deliverByUnixTs":1588271399,"pricePerUnit":30,"qualityMeasure":"","reasonForRejection":"","taxApplicable":{"CGST":{"id":"","taxName":"CGST","taxRate":8,"taxAmount":10800,"isApplicable":true},"IGST":{"id":"","taxName":"","taxRate":0,"taxAmount":0,"isApplicable":false},"SGST":{"id":"","taxName":"SGST","taxRate":8,"taxAmount":10800,"isApplicable":true}},"items":[],"shopOrder":"","totalAmount":0}}}`)
	var result bytes.Buffer

	err := jsonlogic.Apply(logic, data, &result)

	fmt.Println(result.String())
	fmt.Println(err)
}


error :
 panic: interface conversion: interface {} is map[string]interface {}, not []interface {}

goroutine 1 [running]:
github.com/diegoholiveira/jsonlogic.getVar(0x154500, 0x40c178, 0x154e60, 0x43e3e0, 0x0, 0x154e60)
	/tmp/gopath790557694/pkg/mod/github.com/diegoholiveira/[email protected]+incompatible/vars.go:89 +0x740
github.com/diegoholiveira/jsonlogic.operation(0x40e053, 0x3, 0x154500, 0x40c178, 0x154e60, 0x43e3e0, 0x132500, 0x1c8f)
	/tmp/gopath790557694/pkg/mod/github.com/diegoholiveira/[email protected]+incompatible/jsonlogic.go:540 +0x1120
github.com/diegoholiveira/jsonlogic.apply(0x154e60, 0x43e3a0, 0x154e60, 0x43e3e0, 0x277801, 0x15d240)
	/tmp/gopath790557694/pkg/mod/github.com/diegoholiveira/[email protected]+incompatible/jsonlogic.go:708 +0x1e0
github.com/diegoholiveira/jsonlogic.parseValues(0x14d940, 0x40a0f0, 0x154e60, 0x43e3e0, 0x0, 0x1c00)
	/tmp/gopath790557694/pkg/mod/github.com/diegoholiveira/[email protected]+incompatible/jsonlogic.go:674 +0x260
github.com/diegoholiveira/jsonlogic.apply(0x154e60, 0x43e380, 0x154e60, 0x43e3e0, 0x277801, 0x16e9a7)
	/tmp/gopath790557694/pkg/mod/github.com/diegoholiveira/[email protected]+incompatible/jsonlogic.go:708 +0x1a0
github.com/diegoholiveira/jsonlogic.parseValues(0x14d940, 0x40a110, 0x154e60, 0x43e3e0, 0xfefc9a08, 0x0)
	/tmp/gopath790557694/pkg/mod/github.com/diegoholiveira/[email protected]+incompatible/jsonlogic.go:674 +0x260
github.com/diegoholiveira/jsonlogic.apply(0x154e60, 0x43e360, 0x154e60, 0x43e3e0, 0x277801, 0x8)
	/tmp/gopath790557694/pkg/mod/github.com/diegoholiveira/[email protected]+incompatible/jsonlogic.go:708 +0x1a0
github.com/diegoholiveira/jsonlogic.parseValues(0x14d940, 0x40a130, 0x154e60, 0x43e3e0, 0x40e0a0, 0x1010000)
	/tmp/gopath790557694/pkg/mod/github.com/diegoholiveira/[email protected]+incompatible/jsonlogic.go:674 +0x260
github.com/diegoholiveira/jsonlogic.apply(0x154e60, 0x43e340, 0x154e60, 0x43e3e0, 0x277801, 0x1c8f)
	/tmp/gopath790557694/pkg/mod/github.com/diegoholiveira/[email protected]+incompatible/jsonlogic.go:708 +0x1a0
github.com/diegoholiveira/jsonlogic.parseValues(0x14d940, 0x40a140, 0x154e60, 0x43e3e0, 0x16, 0x1c8f)
	/tmp/gopath790557694/pkg/mod/github.com/diegoholiveira/[email protected]+incompatible/jsonlogic.go:674 +0x260
github.com/diegoholiveira/jsonlogic.apply(0x154e60, 0x43e320, 0x154e60, 0x43e3e0, 0x1, 0x0)
	/tmp/gopath790557694/pkg/mod/github.com/diegoholiveira/[email protected]+incompatible/jsonlogic.go:708 +0x1a0
github.com/diegoholiveira/jsonlogic.Apply(0x1c0300, 0x43e2c0, 0x1c0300, 0x43e2e0, 0x1c0140, 0x43e300, 0x1, 0x4)
	/tmp/gopath790557694/pkg/mod/github.com/diegoholiveira/[email protected]+incompatible/jsonlogic.go:736 +0x220
main.main()
	/tmp/sandbox395415131/prog.go:17 +0x140

Unable to use V2 or V3 versions

As pointed out in #35 your go.mod module name needs /v2
This looks to be corrected for V3 but it is very strange that your go.mod for V3 references your own module as github.com/diegoholiveira/jsonlogic v2.3.1+incompatible

https://github.com/diegoholiveira/jsonlogic/blob/v3.0.0/go.mod#L6

We are using Go 1.16 and 1.17 which is not allowing us to use any thing higher than github.com/diegoholiveira/jsonlogic v1.0.1-0.20200220175622-ab7989be08b9 in Edgex Foundry here:

https://github.com/edgexfoundry/app-functions-sdk-go/blob/main/go.mod#L7

Error Operation Equals with Nulls

Error Operation Equals with nulls, which both parameters are null gives me a false response logic := strings.NewReader('{"==": [null, null]}'); but from the operations page operations I get a true response

Checking, there is a condition in the function Equals, indicating that if any is nil, it returns false; which I don't see is the right solution

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.