Created
September 25, 2019 13:13
-
-
Save diegoholiveira/994eddaf479aea0e5c50dc4ac4efdebc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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