json needs to be 'empty' with {}
- Dominant language
- Python
- Stars
- 1k
- Forks
- 131
- PR merge metrics
- No merged PRs in 30d
Description
Why do I need to initialize the json file with a '{}' for the following to work? Is this designed?
It seems to me if i say that if I declare that the file is an (actually) empty file then it should be taken as empty!
```
In [260]: tf=NamedTemporaryFile()
In [261]: j=JSON(tf.name)
In [262]: odo([{'asdf':123}], j)
---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
in ()
----> 1 odo([{'asdf':123}], j)
~/odo/odo/odo.py in odo(source, target, **kwargs)
89 odo.append.append - Add things onto existing things
90 """
---> 91 return into(target, source, **kwargs)
~/miniconda3/envs/py3kio/lib/python3.6/site-packages/multipledispatch/dispatcher.py in __call__(self, *args, **kwargs)
162 self._cache[types] = func
163 try:
--> 164 return func(*args, **kwargs)
165
166 except MDNotImplementedError:
~/odo/odo/into.py in wrapped(*args, **kwargs)
41 raise TypeError('dshape argument is not an instance of DataShape')
42 kwargs['dshape'] = dshape
---> 43 return f(*args, **kwargs)
44 return wrapped
45
~/odo/odo/into.py in into_object(target, source, dshape, **kwargs)
129 if dshape is None:
130 dshape = discover(source)
--> 131 return append(target, source, dshape=dshape, **kwargs)
132
133
~/miniconda3/envs/py3kio/lib/python3.6/site-packages/multipledispatch/dispatcher.py in __call__(self, *args, **kwargs)
162 self._cache[types] = func
163 try:
--> 164 return func(*args, **kwargs)
165
166 except MDNotImplementedError:
~/odo/odo/backends/json.py in list_to_json(j, seq, dshape, encoding, **kwargs)
185 if os.path.exists(j.path):
186 with open(j.path) as f:
--> 187 if json.load(f):
188 raise ValueError("Can only append to empty JSON File.\n"
189 "Either remove contents from this file, save to a new file \n"
~/miniconda3/envs/py3kio/lib/python3.6/json/__init__.py in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
297 cls=cls, object_hook=object_hook,
298 parse_float=parse_float, parse_int=parse_int,
--> 299 parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
300
301
~/miniconda3/envs/py3kio/lib/python3.6/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
352 parse_int is None and parse_float is None and
353 parse_constant is None and object_pairs_hook is None and not kw):
--> 354 return _default_decoder.decode(s)
355 if cls is None:
356 cls = JSONDecoder
~/miniconda3/envs/py3kio/lib/python3.6/json/decoder.py in decode(self, s, _w)
337
338 """
--> 339 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
340 end = _w(s, end).end()
341 if end != len(s):
~/miniconda3/envs/py3kio/lib/python3.6/json/decoder.py in raw_decode(self, s, idx)
355 obj, end = self.scan_once(s, idx)
356 except StopIteration as err:
--> 357 raise JSONDecodeError("Expecting value", s, err.value) from None
358 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.