[Tutor] Parsing JSON with Python
Ben Finney
ben+python at benfinney.id.au
Fri Dec 12 00:15:54 CET 2014
Galen Seilis <galen.seilis at gmail.com> writes:
> I am having difficulty interacting with JSON. The example below if a
> typical input and output:
Thank you for presenting a simple example and the resulting output.
Unfortunately, your mail client has mangled it, inserting asterisks
making syntax errors, and wrapping lines that should be separate.
Please, in future, compose messages only in “plain text” mode. Your text
examples will survive much better that way.
> *import json*
> *array = json.load( { "name": "Joe", "address": "111 Street" } )*
You are passing a Python dict value to the function. JSON is a
serialisation format, and the input to ‘json.load’ must be a text
string.
A literal Python text string looks like this in the code::
"foo bar baz"
A literal Python dict looks like this in the code::
{ "name": "Joe", "address": "111 Street" }
--
\ “For fast acting relief, try slowing down.” —Jane Wagner, via |
`\ Lily Tomlin |
_o__) |
Ben Finney
More information about the Tutor
mailing list