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

Merge command does not merge correctly when using arrays #64

Open
cristinamudura opened this issue Sep 14, 2023 · 2 comments
Open

Merge command does not merge correctly when using arrays #64

cristinamudura opened this issue Sep 14, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@cristinamudura
Copy link
Contributor

cristinamudura commented Sep 14, 2023

Input

{
    "objectWithArrays": [
        {
            "MyFirstObject": [
                {
                    "refKey": "1",
                    "test": "mytest"
                },
                {
                    "refKey": "2",
                    "test": "mytest"
                }
            ],
            "SecondObjectToMergeWith": [
                {
                    "refKey": "1",
                    "testing": "mytesting"
                },
                {
                    "refKey": "2",
                    "testing": "mytesting"
                },
                {
                    "refKey": "3",
                    "testing": "mytesting"
                }
            ]
        },
        {
            "MyFirstObject": [
                {
                    "refKey": "1",
                    "test": "mytest"
                },
                {
                    "refKey": "2",
                    "test": "mytest"
                }
            ],
            "SecondObjectToMergeWith": [
                {
                    "refKey": "1",
                    "testing": "mytesting"
                },
                {
                    "refKey": "2",
                    "testing": "mytesting"
                },
                {
                    "refKey": "3",
                    "testing": "mytesting"
                }
            ]
        }
    ]
}

Script

[
    {
        "path": "$.objectWithArrays[*].SecondObjectToMergeWith",
        "settings": {
            "arraySettings": [
                {
                    "arrayPath": "$.objectWithArrays[*].MyFirstObject",
                    "keyPaths": [
                        "refKey"
                    ],
                    "uniqueItemsWithoutKeys": false
                }
            ],
            "matchSettings": {
                "HasKeys": false,
                "keyPaths": []
            },
            "strategy": "fullMerge" //fullMerge,onlyValues
        },
        "targetPath": "$.objectWithArrays[*].MyFirstObject",
        "command": "merge"
    }
]

Expected Result:

{
    "objectWithArrays": [
        {
            "MyFirstObject": [
                {
                    "refKey": "1",
                    "test": "mytest",
                    "testing": "a"
                },
                {
                    "refKey": "2",
                    "test": "mytest",
                    "testing": "b"
                }
            ],
            "SecondObjectToMergeWith": [
                {
                    "refKey": "1",
                    "testing": "a"
                },
                {
                    "refKey": "2",
                    "testing": "b"
                },
                {
                    "refKey": "3",
                    "testing": "c"
                }
            ]
        },
        {
            "MyFirstObject": [
                {
                    "refKey": "1",
                    "test": "mytest",
                    "testing": "a"
                },
                {
                    "refKey": "2",
                    "test": "mytest",
                    "testing": "b"
                }
            ],
            "SecondObjectToMergeWith": [
                {
                    "refKey": "1",
                    "testing": "a"
                },
                {
                    "refKey": "2",
                    "testing": "b"
                },
                {
                    "refKey": "3",
                    "testing": "c"
                }
            ]
        }
    ]
}
@FransVanEk
Copy link
Contributor

input

{
  "objectWithArrays": [
    {
      "MyFirstObject": [
        {
          "refKey": "1",
          "test": "mytest"
        },
        {
          "refKey": "2",
          "test": "mytest"
        }
      ],
      "SecondObjectToMergeWith": [
        {
          "refKey": "1",
          "testing": "a"
        },
        {
          "refKey": "2",
          "testing": "b"
        },
        {
          "refKey": "3",
          "testing": "c"
        }
      ]
    },
    {
      "MyFirstObject": [
        {
          "refKey": "1",
          "test": "mytest"
        },
        {
          "refKey": "2",
          "test": "mytest"
        }
      ],
      "SecondObjectToMergeWith": [
        {
          "refKey": "1",
          "testing": "d"
        },
        {
          "refKey": "2",
          "testing": "e"
        },
        {
          "refKey": "3",
          "testing": "f"
        }
      ]
    }
  ]
}

should turn into

{
    "objectWithArrays": [
        {
            "MyFirstObject": [
                {
                    "refKey": "1",
                    "test": "mytest",
                    "testing": "a"
                },
                {
                    "refKey": "2",
                    "test": "mytest",
                    "testing": "b"
                }
            ],
            "SecondObjectToMergeWith": [
                {
                    "refKey": "1",
                    "testing": "a"
                },
                {
                    "refKey": "2",
                    "testing": "b"
                },
                {
                    "refKey": "3",
                    "testing": "c"
                }
            ]
        },
        {
            "MyFirstObject": [
                {
                    "refKey": "1",
                    "test": "mytest",
                    "testing": "d"
                },
                {
                    "refKey": "2",
                    "test": "mytest",
                    "testing": "e"
                }
            ],
            "SecondObjectToMergeWith": [
                {
                    "refKey": "1",
                    "testing": "d"
                },
                {
                    "refKey": "2",
                    "testing": "e"
                },
                {
                    "refKey": "3",
                    "testing": "f"
                }
            ]
        }
    ]
}

@FransVanEk
Copy link
Contributor

This is currently not supported. It is a challenging structure with an array in an array. The execution requires it to be handled 0ne by one, while the current implementation works to match all results based on the key provided.
I tried several creative ways to make it work, but to no avail. In order to make this work we have to add some methods to run it for each object separately.

@FransVanEk FransVanEk added the enhancement New feature or request label Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants