jmespath.js icon indicating copy to clipboard operation
jmespath.js copied to clipboard

Do we have function to reconstruct from parsed object?

Open Thaina opened this issue 4 years ago • 0 comments

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

Thaina avatar Oct 02 '19 05:10 Thaina