1

Can someone help me to access myapp from below json using python, please ?

{
    "Data": {
        "Name": "myname",
        "AccountName": "test",
        "classic": [
          {
            "cName": "mycname",
            "tags": ["tag1", "tag2"],
            "Version": "1.14.10",
            "app": "myapp"
        }
        ]
    }
}

3 Answers 3

4

Use json.load for reading a file or json.loads for a string.

data_dict = json.loads(your_data)
print(data_dict["Data"]["classic"][0]["app"])
Sign up to request clarification or add additional context in comments.

Comments

0

Use json loads to parse a json string and json dumps for stringifying the json to a json string

Here in your case you will need json loads

input = {
    "Data": {
        "Name": "myname",
        "AccountName": "test",
        "classic": [
          {
            "cName": "mycname",
            "tags": ["tag1", "tag2"],
            "Version": "1.14.10",
            "app": "myapp"
        }
        ]
    }
}

parsed_input = json.loads(input)
output  = parsed_input["Data"]["classic"][0]["app"]
print(output)

Comments

0

You can use json library for the same.


input_json= {
    "Data": {
        "Name": "myname",
        "AccountName": "test",
        "classic": [
          {
            "cName": "mycname",
            "tags": ["tag1", "tag2"],
            "Version": "1.14.10",
            "app": "myapp"
        }
        ]
    }
}


data = json.loads(input_json)

result=data["Data"]["classic"][0]["app"])

2 Comments

The code is a little difficult to read, could you use a codeblock so that its easier on the eyes?
Does this help?

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.