โ06-14-2017 07:37 AM
I have a json file with an array designed like below. I donโt have control over the number of or order of address entries. I have tried $.Address.findIndex(x => x == โHomeโ) and $.Address ? (value.AddrType = Home) among other expression language statements.
I would like to query the array by AddrType and get the index of the matching array entry record. Has anyone done something similar. We are attempting to normalize<<>>denormalize records based on types to denormalized fields that correspond to the types.
{fnam:โJoeโ,Lname:โLongโ,
Address:[
{
โAddrTypeโ: โMailingโ,
โStreetAddr1โ: โ123 Prospect Streetโ,
โCityโ: โWalthamโ,
โStateโ: โMAโ,
โZipcodeโ: โโ
},
{
โAddrTypeโ: โMainโ,
โStreetAddr1โ: โ123 Baystate Streetโ,
โCityโ: โโ,
โStateโ: โโ,
โZipcodeโ: โโ,
}
]
โ06-14-2017 08:11 AM
Is this the exact expression that you tried?
If so, it wonโt work because you missed the โAddrTypeโ field reference. Something like this should work:
$.Address.findIndex(x => x.AddrType == "Home")
โ06-14-2017 10:38 AM
Works perfectly thank you.