Skip to content

Return nil for missing nested (parent) nodes with :default_path_leaf_to_null #178

Description

@marijastojanovic5

Hi,

I’m using the :default_path_leaf_to_null option, which works well for missing leaf nodes, but it does not return nil when an intermediate (parent) node is missing or is null. Instead, those entries are skipped entirely.

Example

[
  {
    "ID": 1,
    "Name": "Job quote",
    "Salesperson": null,
    "Site": { "ID": 12, "Name": "123 Main Site" }
  },
  {
    "ID": 2,
    "Name": "Test quote",
    "Salesperson": {
      "ID": 134,
      "Name": "Tom Holland",
      "Type": "employee"
    },
    "Site": { "ID": 12, "Name": "123 Main Site" }
  },
  {
    "ID": 3,
    "Name": "Ref data test",
    "Salesperson": null,
    "Site": { "ID": 125, "Name": "Some cool Site" }
  }
]

JsonPath.new('$.Salesperson.Name', default_path_leaf_to_null: true).on(example)

Current result:
["Tom Holland"]

Expected/Desired result:
[nil, "Tom Holland", nil]
(I would like to get nil for missing or null parents, not just missing leaves.)

Is this possible, or could it be considered as a feature?
Thank you!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions