0

I coped the following JSON data from a website, but I don't know how to access it with python.

Screenshot of copied JSON data

The result looks something like this:

5b8e6b4b4f0ca1fbcd66e34e: {parentId: "52ff2e04e4b0b193ed664d45", nodeInfo: {position: 102,…}, id: "5b8e6b4b4f0ca1fbcd66e34e",…}
id: "5b8e6b4b4f0ca1fbcd66e34e"
name: "Parental Control"
nodeInfo: {position: 102,…}
description: "Companies that provide parental control solutions to keep children away from online risks"
position: 102
parentId: "52ff2e04e4b0b193ed664d45"
5b8e7c244f0c6c2263aaf8d2: {parentId: "5330677ae4b09e5482339b7a", nodeInfo: {position: 38,…}, id: "5b8e7c244f0c6c2263aaf8d2",…}
id: "5b8e7c244f0c6c2263aaf8d2"
name: "Anti Spyware"
nodeInfo: {position: 38,…}
description: "Companies that provides tools to remove spyware such as adware, keyboard loggers, hijackers etc"
position: 38
parentId: "5330677ae4b09e5482339b7a"
5b8f9d0f4f0c7c4d2daea8e8: {parentId: "52ff2e3de4b0b193ed664d4a", nodeInfo: {position: 42,…}, id: "5b8f9d0f4f0c7c4d2daea8e8",…}
id: "5b8f9d0f4f0c7c4d2daea8e8"
name: "Anti Theft"
nodeInfo: {position: 42,…}
description: "Companies that provide anti-theft solutions with features such as remote lock, remote wipe, theft detection etc"
position: 42
parentId: "52ff2e3de4b0b193ed664d4a"

How can I get access to the data in python using something like json.load()?

Desired Outputs:

parent = x["parentId"]
name = x["name"]
id = x["id"]

Thanks!!

martineau
  • 119,623
  • 25
  • 170
  • 301
BQuist
  • 171
  • 7
  • 1
    By "copied", I assume you mean you copied and pasted it directly from a browser's developer's tools window? One way would be to make the request directly from your Python code. Another way would be to copy the page/document source instead of copying the text from the nicer looking user interface, to preserve the underlying formatting and structure. – Grismar Jul 13 '22 at 23:50
  • 1
    [Please do not upload images of code/data/errors when asking a question.](http://meta.stackoverflow.com/q/285551) – martineau Jul 14 '22 at 00:01
  • You can validate your json with an online editor such as: https://jsoneditoronline.org/. Then an answer like this should explain how to read it using python: https://stackoverflow.com/questions/20199126/reading-json-from-a-file – David Parks Jul 14 '22 at 00:12
  • Thanks David! I appreciate the resource! – BQuist Jul 14 '22 at 00:14

0 Answers0