0

I'm trying to extract object names from JSON so that I can iterate over them. Here's my JSON:

{
    "Resources": {
        "vpc": {
            "cidr": "192.168.1.0/24",
            "dns_resolution": "TRUE"
        },
        "subnet": {
            "cidr": "192.168.1.0/24",
            "availability_zone": "us-west-1a"
        }
    }
}

This should return an array, like this:

echo ${array[@]}
vpc subnet

1 Answer 1

1

You will need a JSON parser to achieve this. You can use "jq", available on https://stedolan.github.io/jq/

You can play with it before installing it on https://jqplay.org/ , to check it will be able to do what you want, and to learn how.

Sign up to request clarification or add additional context in comments.

1 Comment

Specifically, cat yourdata.json | jq '.Resources | keys | join(" ")' -r should give you the desired output in the original question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.