kazaam
kazaam copied to clipboard
Shift Spec for Root Array
Is it possible to use shift when the root is an array?
Given the json
[{
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"address" : {
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
},
"phoneNumbers": [
{
"type" : "iPhone",
"number": "0123-4567-8888"
},
{
"type" : "home",
"number": "0123-4567-8910"
}
]
}]
And the spec
[{"operation":"shift","spec":{"[*].streetAddress":"[*].address.streetAddress"},"require":false}]
The result is
{"[*]":{"streetAddress":null}}
It should be
[{
"streetAddress": "naist street"
}]
Hi @austinarbor, the right way to handle this is with the "over"
keyword, although this was not totally hooked up before. I believe this will work with the latest release v3.4.9. Kazaam generally was built with the assumption that the input is a JSON object rather than a top level array so I'm not sure whether this will work in all cases, but with the fix it does seem to work for the case you described.
Please confirm whether this now works for your use case, and drop a new issue if you notice any further weirdness for other cases. Here's what I did locally after the fix:
$ cat ~/spec.json
[{"operation":"shift","spec":{"streetAddress":"address.streetAddress"},"require":false,"over":"$"}]
$ cat ~/doc.json
[{
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"address" : {
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
},
"phoneNumbers": [
{
"type" : "iPhone",
"number": "0123-4567-8888"
},
{
"type" : "home",
"number": "0123-4567-8910"
}
]
}]
$ ./kazaam -spec ~/spec.json -in ~/doc.json
[{"streetAddress":"naist street"}]
@JoshKCarroll thanks! this looks good. i did have some other observations but i'll open another issue for those