Two lines of code will make the JSON response easier to read.
You can use Pandas to better format and explore your JSON responses, but if you just need to quickly make the JSON message more readable, use the following code instead of print(response)
:
# Format the JSON response and printimport jsonprint(json.dumps(response, indent=2))
A full code sample, using the above code snippet and calling the structure
endpoint, looks like this:
# Call the API's structure endpointfrom scienceio import ScienceIOscio = ScienceIO()query_text = ("ALS is often called Lou Gehrig's disease, after the baseball player who was diagnosed with it. Doctors usually do not know why ALS occurs.")response = scio.structure(query_text)# Format the JSON response and printimport jsonprint(json.dumps(response, indent=2))
Use numbers to increase or decrease the indent. You could use, for example, a 7 to greatly increase the indent from 2 (print(json.dumps(response, indent=7))
), or a 1 to slightly decrease it from 2 (print(json.dumps(response, indent=1))
).
Feedback
Was this page helpful?
Great! If you ever have questions or want to provide feedback, send us an email.
Bummer. We hate when we miss the mark. If you have suggestions for improvements or other general comments, send us an email.