Issue in reading JSON file in python
Question: 
    >>> import json
    >>> d2 = json.loads(open("t.json").read())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib64/python2.6/json/__init__.py", line 307, in loads
        return _default_decoder.decode(s)
      File "/usr/lib64/python2.6/json/decoder.py", line 319, in decode
        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
      File "/usr/lib64/python2.6/json/decoder.py", line 336, in raw_decode
        obj, end = self._scanner.iterscan(s, **kw).next()
      File "/usr/lib64/python2.6/json/scanner.py", line 55, in iterscan
        rval, next_pos = action(m, context)
      File "/usr/lib64/python2.6/json/decoder.py", line 185, in JSONObject
        raise ValueError(errmsg("Expecting object", s, end))
    ValueError: Expecting object: line 1 column 11 (char 11)
    [ RHEL - ~/testing ]$ cat t.json
    {"us": u"OFF", "val": u"5"}
    

Here is what I have in my JSON file and when I try to read it using `open` and
`json.load` and json.loads it fails.

After using json.load

    
    
    >>> import json
    >>> d2 = json.load(open("t.json"))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib64/python2.6/json/__init__.py", line 267, in load
        parse_constant=parse_constant, **kw)
      File "/usr/lib64/python2.6/json/__init__.py", line 307, in loads
        return _default_decoder.decode(s)
      File "/usr/lib64/python2.6/json/decoder.py", line 319, in decode
        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
      File "/usr/lib64/python2.6/json/decoder.py", line 336, in raw_decode
        obj, end = self._scanner.iterscan(s, **kw).next()
      File "/usr/lib64/python2.6/json/scanner.py", line 55, in iterscan
        rval, next_pos = action(m, context)
      File "/usr/lib64/python2.6/json/decoder.py", line 185, in JSONObject
        raise ValueError(errmsg("Expecting object", s, end))
    ValueError: Expecting object: line 1 column 11 (char 11)
    >>>
    


Answer: You are using the wrong function. Use `json.load()` (no `s`!) to load data
from an open file object:

    
    
    d2 = json.load(open("t.json"))
    

The `json.loads()` function expects you to pass in a _string_ , not a file
object. You'd have to read your file in that case, returning the read data:

    
    
    d2 = json.loads(open("t.json").read())
    

Next, you have invalid JSON in that file:

    
    
    {"us": u"OFF", "val": u"5"}
    #      ^              ^
    

JSON is not Python; those `u` prefixes are not supported nor needed. You'll
need to remove those from the file before it'll load.

If you have an API producing that format, it is not giving you JSON. It could
be that it is producing a (strange form of) Python syntax instead; Python
itself would produce `{'us': u'OFF', 'val': u'5'}` (single quotes). You can
have Python interpret that as Python literals with
[`ast.literal_eval()`](https://docs.python.org/2/library/ast.html#ast.literal_eval):

    
    
    import ast
    
    with open('t.json') as fileobj:
        d2 = ast.literal_eval(fileobj.read())
    

but it could be that the format is broken in other ways we cannot determine
from a single isolated sample. It could be using `true` and `false` for
boolean values, like in JSON, for example.

Better to have the _API_ fixed rather that try and work around this broken-
ness.

