4 ms·
Powershell has the upper hand here! Still, bash can try to keep up using json.bash. :) $ source json.bash $ declare -A greeting=([Hello]=World) $
by h4l 2y ago
Powershell has the upper hand here!
Still, bash can try to keep up using json.bash. :)
$ source json.bash
$ declare -A greeting=([Hello]=World)
$ json ...@greeting:{}
{"Hello":"World"}
... is splatting the greeting associative array entries into the object created by the json call.
Without the ... the greeting would be a nested object. Probably more clear with multiple entries:
$ declare -A greeting=([Hello]=World [How]="are you?")
$ json @greeting:{}
{"greeting":{"Hello":"World","How":"are you?"}}
Vs:
$ json ...@greeting:{}
{"Hello":"World","How":"are you?"}
- majkinetor 2y ago$h=@{x=1; y=2}; $h + @{z=3} | ConvertTo-Json { "y": 2, "z": 3, "x": 1 } You can even use [ordered]$h to make keys not go random place.