JSONPath-Plus / JSONPath

A fork of JSONPath from http://goessner.net/articles/JsonPath/
Other
975 stars 175 forks source link

allow easy data editing via callback #133

Open mknj opened 4 years ago

mknj commented 4 years ago

Motivation

I want to change all found elements via a callback. (i.e. rewrite $ref: ) other libraries have an apply(...,callback) method, that allows to change values easily by updating the value with the callback return value.

Current behavior

In this example I want to double all found values.

{ callback: (v,_dummy,p)=>p.parent[p.parentProperty]=v*2 }

This syntax is especially bad if you work with typescript and eslint no_unused_var

Desired behavior

{ applycb: (v)=>v*2 }
rattrayalex commented 1 year ago

An example of how to do this yourself is here: https://github.com/JSONPath-Plus/JSONPath/issues/163#issuecomment-1366172817

Let me know if you have any issues with it…