Description
Is your feature request related to a problem? Please describe.
I often use dasel to mangle test data, and would like to be able to vary the values that I'm put
ing into the output.
Describe the solution you'd like
I'd like to be able to specify a node selector string in the value.
cat input.json | dasel put -p json string -m -V '"Item" .[]' '.Items.[*].Name'
Where -V
(or some other flag) tells dasel to run the query on the current node and use the result as the value. This example would set the attribute "Name": "Item <index>"
for each Item
object in the Items
array.
Describe alternatives you've considered
If the set is large enough, I'd write a Ruby or awk script. My test sets tend to be small, so I usually just edit them by hand.
I also considered using --merge-input-documents
, but I don't believe it'd replace the existing objects -- just add to them. In any case, it'd be fairly involved to create the merge document, and possibly more trouble than writing code to modify the data.
Additional context
I'd like to turn this:
{"name": "Real data",
"things": {
{"title": "foo", "id": 4843},
{"title": "top secret", "id": 4448},
{"title": "blah", "id": 3333}
}}
into this:
{"name": "Fake data",
"things": {
{"title": "thing 1", "id": 1},
{"title": "thing 2", "id": 2},
{"title": "thing 3", "id": 3}
}}