Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9237707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:35:39+00:00 2026-06-18T07:35:39+00:00

I need to extract some information from json strings in bash. The json-strings are

  • 0

I need to extract some information from json strings in bash. The json-strings are like

{"ok":true,"id":"af1aa5cef5dc0c86fd734ff3d42a8188","rev":"1-f28941b049d7d356ae113fa061ddfe1f"}

(outputs from a couchdb insert)

I want to grab just the id, so I tried to

$IFS=;,\" 
json=tail -n1 output
echo $json 
\\ { ok  true  id   af1aa5cef5dc0c86fd734ff3d42a8188   rev   1-f28941b049d7d356ae113fa061ddfe1f }

So, so far, all seems fine and dandy, but, if I try to access an element, ${json[0]} returns the entire string, whereas all other ${json[n]}s are empty.

On the other hand,

for i in $json;
 do echo $i
done

Works with each element of $json…

I must be doing something wrong, but what?

(And yes, I do know this kind of “parsing” of a json string will get me into problems with something just slightly more complicated – but for these strings it should work fine – I thought)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:35:40+00:00Added an answer on June 18, 2026 at 7:35 am

    You can use awk:

    $ echo '"ok":true,"id":"af1aa5cef5dc0c86fd734ff3d42a8188","rev":"1-f28941b049d7d356ae113fa061ddfe1f"}' | awk -F, '{ print $2 }'
    "id":"af1aa5cef5dc0c86fd734ff3d42a8188"
    

    You can also you two delimiters with awk

     $ awk -F'[,:]' '{ print $4 }' your_json_file.json
    "af1aa5cef5dc0c86fd734ff3d42a8188"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use an awk script to extract some information from a file.
I am trying to extract some information from a binary file. It looks like
I need to extract information from an LDAP connection string like this one: ldap://uid=adminuser,dc=example,c=com:secret@ldap.example.com/dc=basePath,dc=example,c=com
I need to extract some management information (MI) from data which is updated in
i need to extract some information from a pdf stream. It's quite simple to
I've a document from which I need to extract some data. Document contain strings
I have a 1.3GB text file that I need to extract some information from
I need to extract some information from not very complicated HTML pages in web.
Need to extract .co.uk urls from a file with lots of entries, some .com
I grabbed some information from an RSS feed in XML. I need some help

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.