I want to combine following 2 JSON files below:
This is the first JSON File which is the original JSON file
{
"toolcache": [
{
"name": "Python",
"platform" : "linux",
"platform_version": "22.04",
"versions": [
"3.7.*"
]
}
],
"android": {
"ndk": {
"default": "23",
"versions": [
"21", "23", "24"
]
}
},
"powershellModules": [
{"name": "Pester"},
{"name": "PSScriptAnalyzer"}
],
"docker": {
"images": [
"alpine:3.14",
"alpine:3.15",
"buildpack-deps:buster",
"buildpack-deps:bullseye",
"debian:10",
"debian:11",
"moby/buildkit:latest",
"node:14",
"node:16",
"node:14-alpine",
"node:16-alpine"
]
},
"postgresql": {
"version": "14"
}
}
This is the second JSON File which we can update and we expect it to merge / add to the original first JSON File
{
"toolcache": [
{
"name": "node",
"platform" : "linux",
"versions": [
"16.*"
]
}
],
"android": {
"cmdline-tools": "latest",
"platform_min_version": "27",
"build_tools_min_version": "27.0.0",
"extra_list": [
"android;m2repository",
"google;m2repository",
"google;google_play_services"
],
"addon_list": [
],
"additional_tools": [
"cmake;3.10.2.4988404",
"cmake;3.18.1"
]
},
"powershellModules": [
{"name": "MarkdownPS"},
{"name": "Microsoft.Graph"}
],
"docker": {
"images": [
"ubuntu:18.04",
"ubuntu:20.04",
"ubuntu:22.04"
]
}
}
Here is the expected result:
{
"toolcache": [
{
"name": "Python",
"platform" : "linux",
"platform_version": "22.04",
"versions": [
"3.7.*"
]
},
{
"name": "node",
"platform" : "linux",
"versions": [
"16.*"
]
}
],
"android": {
"cmdline-tools": "latest",
"platform_min_version": "27",
"build_tools_min_version": "27.0.0",
"extra_list": [
"android;m2repository",
"google;m2repository",
"google;google_play_services"
],
"addon_list": [
],
"additional_tools": [
"cmake;3.10.2.4988404",
"cmake;3.18.1"
],
"ndk": {
"default": "23",
"versions": [
"21", "23", "24"
]
}
},
"powershellModules": [
{"name": "Pester"},
{"name": "PSScriptAnalyzer"},
{"name": "MarkdownPS"},
{"name": "Microsoft.Graph"}
],
"docker": {
"images": [
"alpine:3.14",
"alpine:3.15",
"buildpack-deps:buster",
"buildpack-deps:bullseye",
"debian:10",
"debian:11",
"moby/buildkit:latest",
"node:14",
"node:16",
"node:14-alpine",
"node:16-alpine",
"ubuntu:18.04",
"ubuntu:20.04",
"ubuntu:22.04"
]
},
"postgresql": {
"version": "14"
}
}
I am not too sure if it is possible to add both JSON File together as I've only seen ways to merge while overwriting the existing JSON File. I have also tried Join Object and @($source; $extend) but it was not that simple as it would just create a duplicate.
I am try to experiment with Add-Member but I am now stuck. Any help would be much appreciated.
toolcache->versions->3.8.*. Is this a mistake?