This question appears to be off-topic. The users who voted to close gave this specific reason:

"This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – EJoshuaS, manish, U9-Forward, Graviton, Daniel Pryden

Nice but python adds a u' before each key. Any idea why?
– CodyBugsteinJul 5 '15 at 7:14

7

That is why your text is type unicode not string. Most time it is better to have text in unicode for german umlauts and for sharing text results with other modules/programs etc. . So you're good!
– Michael PAug 29 '15 at 11:56

Note that this only works in Python 2.6 and up, as it depends upon the with-statement. In Python 2.5 use from __future__ import with_statement, in Python <= 2.4, see Justin Peel's answer, which this answer is based upon.

@SteveS. Yes, but not before the context is left. pprinting in the with-context keeps the data_file open longer.
– BengtJun 16 '15 at 17:45

1

@GayanPathirage you access it like data["om_points"] , data["masks"]["id"]. The idea is you can reach any level in a dictionary by specifying the 'key paths'. If you get a KeyError exception it means the key doesn't exist in the path. Look out for typos or check the structure of your dictionary.
– NuhmanMay 25 '18 at 4:55

This answer read whole file to memory when is does not have to and suggests that in Python 3 JSON files cannot be read lazily, which is untrue. I'm sorry, but it's clear downvote.
– Łukasz RogalskiAug 2 '16 at 9:41

7

This answer isn't accurate. There's no reason not to use json.load with an open file handler in python3. Sorry for the downvote, but it doesn't seem like you read the above comments very carefully.
– dusktreaderSep 30 '16 at 21:21

5

+1 This answer is great! Thank you for that and pulled me from going far for looking for a function that can use strings cause I only work with strings and network request that are not file!
– newpeopleJul 28 '17 at 14:42

this is the correct solution if you have multiple json objects in a file. json.loads does not decode multiple json objects. Otherwise, you get 'Extra Data' error.
– yasin_almMar 21 '16 at 21:43

This is the best answer. Otherwise, it gives 'Extra Data' error.
– Earthx9Jun 11 '16 at 12:05

34

Having mutliple json objects in a file means that the file itself is not actually valid json. If you have multiple objects to include in a json file, they should be contained in an array at the top level of the file.
– dusktreaderSep 30 '16 at 21:23

"Ultra JSON" or simply "ujson" can handle having [] in your JSON file input. If you're reading a JSON input file into your program as a list of JSON elements; such as, [{[{}]}, {}, [], etc...] ujson can handle any arbitrary order of lists of dictionaries, dictionaries of lists.

You can find ujson in the Python package index and the API is almost identical to Python's built-in json library.

ujson is also much faster if you're loading larger JSON files. You can see the performance details in comparison to other Python JSON libraries in the same link provided.