Skip to content

Instantly share code, notes, and snippets.

@diegoholiveira
Created September 25, 2019 13:13
Show Gist options
  • Save diegoholiveira/994eddaf479aea0e5c50dc4ac4efdebc to your computer and use it in GitHub Desktop.
Save diegoholiveira/994eddaf479aea0e5c50dc4ac4efdebc to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"fmt"
"strings"
"github.com/diegoholiveira/jsonlogic"
)
func main() {
jsonOriginal := `{
"paymentMethods": [
{
"name": "payment.method.creditcard.visa",
"installments": "1",
"amount": 19,
"discount": 0,
"addition": 0,
"boletoRule": null,
"interestValue": 0,
"boletoUrl": "teste",
"creditCardToken": null
}
]
}`
data := strings.NewReader(jsonOriginal)
var result bytes.Buffer
logic := strings.NewReader(`{"if":[
{"some": [
{"var": "paymentMethods"},
{"==": [
{"var": ".name"},
"payment.method.creditcard.mastercard"
]}
]},
"encontrou",
"não encontrou"
]}`)
err := jsonlogic.Apply(logic, data, &result)
if err != nil {
panic(err)
}
fmt.Println(result.String())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment