JavaScript parser for parsing RQB (react-querybuilder) JSON into expr (expr-lang) expressions
RQBParser.parse(rqbJson)
Input:
{
"combinator": "and",
"not": false,
"rules": [
{
"field": "firstName",
"value": "Stev",
"operator": "beginsWith"
},
{
"field": "lastName",
"value": "Vai, Vaughan",
"operator": "in"
},
{
"field": "age",
"value": "4,55",
"operator": "between"
},
{
"field": "age",
"operator": ">",
"value": "5"
},
{
"combinator": "or",
"rules": [
{
"field": "isMusician",
"operator": "=",
"value": true
},
{
"field": "instrument",
"operator": "=",
"value": "Guitar"
}
]
},
{
"field": "groupedField1",
"operator": "=",
"value": "groupedField2",
"valueSource": "field"
},
{
"field": "birthdate",
"operator": "notBetween",
"value": "1954-10-03,1960-06-06"
},
{
"field": "job",
"operator": "=",
"valueSource": "value",
"value": "developer"
},
{
"rules": [
{
"field": "instrument",
"operator": "=",
"valueSource": "value",
"value": "Cowbell"
},
{
"field": "alsoPlays",
"operator": "in",
"valueSource": "value",
"value": "Cowbell,More cowbell,Spoon,Wooden fish,Ocarina"
}
],
"combinator": "or",
"not": false
}
]
}
Result:
firstName startsWith "Stev"
and (lastName in ["Vai"," Vaughan"])
and (age >= 4 and age <= 55)
and age > 5
and (isMusician == true or instrument == "Guitar")
and groupedField1 == groupedField2
and (birthdate < "1954-10-03" and birthdate > "1960-06-06")
and job == "developer"
and (instrument == "Cowbell" or (alsoPlays in ["Cowbell","More cowbell","Spoon","Wooden fish","Ocarina"]))