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

Prevent empty object elements in array #296

Open
poostwoud opened this issue Feb 14, 2024 · 1 comment
Open

Prevent empty object elements in array #296

poostwoud opened this issue Feb 14, 2024 · 1 comment

Comments

@poostwoud
Copy link

Hi,

Given the following input:

{
  "PropA": "a",
  "PropB": "b",
  "PropC": "c",
  //"PropD": "d",
  "PropE": "e"
}

And transformation:

{
  "PropA": "#valueof($.PropA)",
  "PropB": "#valueof($.PropB)",
  "Props": [
    {
      "#ifgroup(#exists($.PropC))": {
        "Name": "PropC",
        "Value": "#valueof($.PropC)"
      }
    },
    {
      "#ifgroup(#exists($.PropD))": {
        "Name": "PropD",
        "Value": "#valueof($.PropD)"
      }
    },
    {
      "#ifgroup(#exists($.PropE))": {
        "Name": "PropE",
        "Value": "#valueof($.PropE)"
      }
    }
  ]
}

I'm getting the following output:

{
	"PropA": "a",
	"PropB": "b",
	"Props": [
		{
			"Name": "PropC",
			"Value": "c"
		},
		{},
		{
			"Name": "PropE",
			"Value": "e"
		}
	]
}

Where PropD is transformed as an empty object element.

Is there a way to prevent this, or should I just do a second transformation that removes the empty element?

Cheers!

@Courela
Copy link
Contributor

Courela commented Feb 17, 2024

Currently #ifgroup always return an array, even if it's empty.
Maybe an EvaluationMode for this would be handy...

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