Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update readme #68

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 11 additions & 45 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Go JSON Logic
# Go JsonLogic

![test workflow](https://github.com/diegoholiveira/jsonlogic/actions/workflows/test.yml/badge.svg)
[![codecov](https://codecov.io/gh/diegoholiveira/jsonlogic/branch/master/graph/badge.svg)](https://codecov.io/gh/diegoholiveira/jsonlogic)
[![Go Report Card](https://goreportcard.com/badge/github.com/diegoholiveira/jsonlogic)](https://goreportcard.com/report/github.com/diegoholiveira/jsonlogic)

Implementation of [JSON Logic](http://jsonlogic.com) in Go Lang.
Implementation of [JsonLogic](http://jsonlogic.com) in Go Lang.

## What's JSON Logic?
## What's JsonLogic?

JSON Logic is a DSL to write logic decisions in JSON. It's has a great specification and is very simple to learn.
The [official website](http://jsonlogic.com) has a great documentation with examples.
JsonLogic is a DSL to write logic decisions in JSON. It's has a great specification and is very simple to learn.
The [official website](http://jsonlogic.com) has great documentation with examples.

## How to use it

Expand Down Expand Up @@ -104,7 +104,7 @@ func main() {
}
```

If you have a function you want to expose as a JSON Logic operation, you can use:
If you have a function you want to expose as a JsonLogic operation, you can use:

```go
package main
Expand Down Expand Up @@ -138,7 +138,7 @@ func main() {
}
```

If you want to get the json logic used, with the variables replaced by their values :
If you want to get the JsonLogic used, with the variables replaced by their values:

```go
package main
Expand All @@ -156,48 +156,14 @@ func main() {

result, err := jsonlogic.GetJsonLogicWithSolvedVars(logic, data)

if err != nil {
fmt.Println(err)
}
if err != nil {
fmt.Println(err)
}

fmt.Println(string(result)) // will output { "==":[false, true] }
}

```

# License

This project is licensed under the MIT License - see the LICENSE file for details



For example, if you specify the folowing rules model :


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

```

You will get as output, the folowing response (using a specific data, all variables will be replaced with matching values) :

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

```
This project is licensed under the MIT License - see [LICENSE](./LICENSE) for details.
Loading