Skip to content

Recommendation: Replace JSON Pointer notation with JSON Path #34

@dubnemo

Description

@dubnemo

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions