Home > Software design >  Bash Extract 1st key of the json
Bash Extract 1st key of the json

Time:11-18

Hi I need to extract the 1st key of the output json I've tried with different regex but didn't give expected results could you please let me to solve this.

      LANGUAGES=`curl  \
      --request GET \
      --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
      --header 'content-type: application/string' \
      --url 'https://api.github.com/repos/${{ github.repository }}/languages' \
      `
      echo "$LANGUAGES" | regex

outputs and keys will be dynamic

{
    "HCL": 56543,
    "Shell": 22986,
    "Dockerfile": 307
}

Expected output : HCL

{
    "Java": 56543,
    "C  ": 22986,
    "C#": 307
}

Expected output : Java

{
    "Python": 56543,
    "SHELL": 22986,
    "C": 307
}

Expected output : Python

CodePudding user response:

echo "$LANGUAGES" | jq -r 'keys_unsorted | first'
  • Related