Closed cesco69 closed 1 year ago
Is it possible use JSONPath for build an object starting from empty object?
EG:
const data = {}; // start from empty object const updater = (cb: (value: string) => string): JSONPathCallback => (value, _, { parent, parentProperty }) => { parent[parentProperty] = cb(value); return parent; } // add in book object author name Foo Bar const r = JSONPath({ path: '$.book.author', json: data, callback: updater(() => 'Foo Bar'), }); console.log(data)
expected output
{ book: { author: 'Foo Bar' } }
output
{}
Try something instead like https://www.npmjs.com/package/nested-property#nestedpropertysetdata-path-value .
Is it possible use JSONPath for build an object starting from empty object?
EG:
expected output
output