nexxbiz / JLio

The project aims to be able to run a JSON noted transformation script to transform other JSON objects.
https://JLio.online
MIT License
5 stars 1 forks source link

Merge command does not merge correctly when using arrays #64

Open cristinamudura opened 1 year ago

cristinamudura commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.