I have the following JSON data:
{ "Name": "No.reply", "Email": "[email protected]", "ID": 5930, "details": { "message": "Your name: john doe\nEmail: [email protected]\nSubject: I need help with this\nDescription: I can find the download for the manual but I can only find the free updater for Windows or Mac. Can you help me please as I have a chrome notebook and Moto smart phone. Thank you. John doe" } }
The name and email fields from the top level are irrelevant, as they are from the automated email. The information I need is in the message field and in the ID field, which is related to John Doe's info.
Anyway, this is what I need to be filtered and how it should be saved to a new file in this order:
- Name: it should read the lines after this variable, regardless of the text.
- Email: same as above
- Subject: same as above
- Description: same as above
- ID: same as above
So, I need to remove the quotes, the newline character, assign those specific strings to a variable via bash, and read what it's after those strings.
I was able to come up with something, but it doesn't work for this JSON output: (only works if the text file is properly formatted)
while IFS=''
do case "$line" in
"Name:"*) uservar="${line#*: }" ;;
"Email:"*) emailvar="${line#*: }" ;;
"Subject:"*) subject="${line#*: }" ;;
"Message:"*) message="${line#*: }" ;;
"ID:"*) ticketidvar="${line#*: }" ;;
esac
done <<-EOF
$(pbpaste)
EOF
"ID": 5930
?details
field is irrelevant, but you appear to want to extract "your name", "subject" and "description" frommessage
, which is insidedetails
. Which is true? And which email do you want: the top-levelEmail
member ("no.reply") or the one insidemessage
("johndoe")?message
, so I'll need theEmail
info insidemessage
(john doe). The no.reply information is to be ignored. Thank you!