I have two .Json
files I need to merge into one .Json
file:
The first file start.json
looks like this:
{
"MOUSE GESTURE L Start": {
"prefix": "MOUSE GESTURE L Start To Start",
"body": [
"MG_Start()"
],
"description": "Start Cursor back to its start"
}
}
The second file end.json
looks like this:
{
"MOUSE GESTURE L Move To end": {
"prefix": "MOUSE GESTURE L Move To end",
"body": [
"MG_Move()"
],
"description": "Move Cursor back to its end"
}
}
The Expected out I am aiming for is:
{
"MOUSE GESTURE L Start": {
"prefix": "MOUSE GESTURE L Start To Start",
"body": [
"MG_Start()"
],
"description": "Start Cursor back to its start"
}
"MOUSE GESTURE L Move To end": {
"prefix": "MOUSE GESTURE L Move To end",
"body": [
"MG_Move()"
],
"description": "Move Cursor back to its end"
}
}
I have tried:
$Jstart = (Get-Content .\start.json -Raw) | ConvertFrom-Json
$JEnd = (Get-Content .\end.json -Raw) | ConvertFrom-Json
$Hash = [PSCustomObject]@{
$Jstart = (Get-Content .\start.json -Raw) | ConvertFrom-Json
$JEnd = (Get-Content .\end.json -Raw) | ConvertFrom-Json
}
but I get a undesired jumbled output:
{
"@{MOUSE GESTURE L Start=}": {
"MOUSE GESTURE L Start": {
"prefix": "MOUSE GESTURE L Start To Start",
"body": "MG_Start()",
"description": "Start Cursor back to its start"
}
},
"@{MOUSE GESTURE L Move To end=}": {
"MOUSE GESTURE L Move To end": {
"prefix": "MOUSE GESTURE L Move To end",
"body": "MG_Move()",
"description": "Move Cursor back to its end"
}
}
}
I've tried variations but things just get worse. Any ideas on how I can get this right? Thank you
EDIT:
@Santiago Squarzon
While solution works for the example I provided, I am getting problems trying to adapt it to my code.
The prblem I am having is, if one of the .Json
files happens to have more than one object in it, like this:
{
"MOUSE GESTURE L Move To end": {
"prefix": "MOUSE GESTURE L Move To end",
"body": [
"MG_Move()"
],
"description": "Move Cursor back to its end"
},
"Another Snippet": {
"prefix": "MOUSE GESTURE L Move To end",
"body": [
"MG_Move()"
],
"description": "Move Cursor back to its end"
}
}
Then $left.PSObject.Properties.Add($($right.PSObject.Properties))
failss, I get the error:
MethodException:
Cannot find an overload for "Add" and the argument count: "1".