jmespath / jmespath.js

Javascript implementation of JMESPath, a query language for JSON
http://jmespath.org
Other
776 stars 95 forks source link

Do we have function to reconstruct from parsed object? #55

Open Thaina opened 4 years ago

Thaina commented 4 years ago

While we could parse the expression into object. I wish that we should be able to also reconstruct the object that was parsed back to expression. So I could write editor and perform some editing, or just partially reconstruct the subexpression into string text

Suppose I have expression propertyA.valueA > `10`

var expression0 = "propertyA.valueA > `10`";
var parsed = jmespath.parse(expression0);

parsed.name = parsed.name == "GT" ? "LT" : "GT";

var expression1 = jmespath.reconstruct(parsed); // became "propertyA.valueA < `10`";

var subExpression = jmespath.reconstruct(parsed.children[0]); // get "propertyA.valueA"
parsed.children[0].name = subExpression == "propertyA.valueA" ? "propertyB.valueB" : "propertyA.valueA";

var expression2 = jmespath.reconstruct(parsed); // became "propertyB.valueB < `10`";

Is it already possible? If not I would like to have this be feature request