-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
JSON pointer, while is works, requires pre-processing when working with arrays, to determine the index value.
The JSON Path approaches provides filtering that can identity the arrary entry.
{
"phoneNumbers": [
{
"type" : "Work",
"number": "0123-4567-8888"
},
{
"type" : "Mobile",
"number": "0123-4567-8888"
},
{
"type" : "Home",
"number": "0123-4567-8910"
}
]
}
$.phoneNumbers[[email protected] == 'Work'].number will return the correct number to update.
You will have to write code to find the index value would need to be updated via JSON Pointer, in the previous case it would be:
/phoneNumbers/0/number
But for this scenario:
{
"phoneNumbers": [
{
"type" : "Mobile",
"number": "0123-4567-8888"
},
{
"type" : "Home",
"number": "0123-4567-8888"
},
{
"type" : "Work",
"number": "0123-4567-8910"
}
]
}
the JSON Pointer would be:
/phoneNumbers/2/number
as the Work array entry has an index value of 2.
JSON Path is much more robust than JSON Pointer, and would greatly improve JSON Patch.
Metadata
Metadata
Assignees
Labels
No labels