Hacker News new | past | comments | ask | show | jobs | submit login

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?"}





    $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.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: