0

I want to parse below json array and store property of object in array of shell script variable.

{
   "student_profile":[
      {
         "fname":"abc",
         "lname":"xyz"
      },
      {
         "fname":"def",
         "lname":"pqr"
      }
   ]
}

Below is my sh file.

myfile.sh

#!/bin/bash

declare -a names=()

###### Acess and parse json file here and store fname inside the name array

ProBot
  • 133
  • 2
  • 12
  • From the linked duplicate, instead of feeding input from a string using `<<<`, you use the syntax as `jq -r '.student_profile[].fname' json_file` – Inian Jul 31 '20 at 08:12
  • `mapfile -t names < <(jq -r '.student_profile[].fname' file.json); printf '%s\n' "${names[@]}"` – Jetchisel Jul 31 '20 at 08:39

0 Answers0