Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

squashNulls and recursivelySquashNulls need to work on arrays #1255

Open
samer1977 opened this issue May 16, 2024 · 1 comment
Open

squashNulls and recursivelySquashNulls need to work on arrays #1255

samer1977 opened this issue May 16, 2024 · 1 comment

Comments

@samer1977
Copy link

Hi,

There should be a way to make the squashNulls \recursivelySquashNulls remove null objects from an array.

Example:

Input:

{
  "items": [
    1,
    null,
    2
  ]
}

Spec:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "items": "=recursivelySquashNulls" //squashNulls same thing
    }
  }
]

Output:


{
  "items" : [ 1, null, 2 ]
}

Expected:


{
  "items" : [ 1,  2 ]
}

The only way to resolve this is through shift operation which can get cumbersome if the array is nested in a deeper level and is part of complex json where you not only have to traverse the hierarchy but also accommodate all other fields\objects in the spec to maintain the same structure.

@gbouget
Copy link

gbouget commented Jun 4, 2024

A trick is to use a temporary parent node because recursivelySquashNulls only works on child nodes.

[
  {
    "operation": "shift",
    "spec": {
      "*": "tmpRoot.&"
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "tmpRoot": "=recursivelySquashNulls" //squashNulls same thing
    }
  },
  {
    "operation": "shift",
    "spec": {
      "tmpRoot": {
        "*": "&"
      }
    }
  }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants