jsonshellbase64decode

Decoding JSON and a base64-encoded value in a shell script


I have a JSON and I need to extract a base64-encoded value by particular key and decode it.

JSON has the following structure:

[
  {
    "LockIndex": 0,
    "Key": "Arul/key1",
    "Flags": 0,
    "Value": "MzAKCg==",
    "CreateIndex": 369,
    "ModifyIndex": 554
  }
]

In the above JSON, I need to extract only "Value":"MzAKCg==" and decode the base64-encoded "MzAKCg==" value. I would like to perform this using shell scripting.

Please assist.


Solution

  • Using jq and base64:

    jq -r '.[].Value' < file.json | base64 --decode