title: Convert JSON from AWS SSM to environment variables using jq
body: <p>I have done some research on this and feel as if I'm about 80% there but struggling to adjust the jq output as required due to splitting one of the strings.</p>
  
  <p>I'm trying to convert the JSON output from AWS SSM to environment variables. </p>
  
  <p>AWS command </p>
  
  <pre><code>aws ssm get-parameters-by-path \
  --path /qa/es \
  --with-decryption \
  --query 'Parameters[*].{Name:Name,Value:Value}' \
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>[
      {
          "Name": "/qa/es/AWS_ACCESS_KEY_ID",
          "Value": "ABC123"
      },
      {
          "Name": "/qa/es/AWS_SECRET_ACCESS_KEY",
          "Value": "abcdefghijkl"
      },
      {
          "Name": "/qa/es/ENDPOINT",
          "Value": "https://amazonaws.com"
      }
  ]
  </code></pre>
  
  <p>My required output from jq, note I'm only after the environment variable AFTER the last /. There may be cases where this could be /qa/es/something/nested/ENV_VAR</p>
  
  <pre><code>AWS_ACCESS_KEY_ID=ABC123
  AWS_SECRET_ACCESS_KEY=abcdefghijkl
  ENDPOINT=https://amazonaws.com
  </code></pre>
  
  <p>Once I have this I can utilise the answer here to set the environment variables. <a href="https://stackoverflow.com/questions/48512914/exporting-json-to-environment-variables/48515341?noredirect=1#comment84051241_48515341">Exporting JSON to environment variables</a></p>
  
  <p>The closest I have got is </p>
  
  <pre><code>jq -r "map(\"\(try(.Name |= split(\"/\")))=\(.Value|tostring)\")|.[]" params.json
  </code></pre>
  
  <p>Which gives me </p>
  
  <pre><code>{"Name":["","qa","es","AWS_ACCESS_KEY_ID"],"Value":"ABC123"}=ABC123
  {"Name":["","qa","es","AWS_SECRET_ACCESS_KEY"],"Value":"abcdefghijkl"}=abcdefghijkl
  {"Name":["","qa","es","ENDPOINT"],"Value":"https://amazonaws.com"}=https://amazonaws.com
  </code></pre>
  
  <p>Close, but not close enough! Can anyone point me in the right direction here?</p>