I believe you meant to open the file first and then read it into data_processed
.
with open("C:\Users\me\Documents\myfile.json") as fp:
data_processed = json.load(fp)
I believe you meant to open the file first and then read it into data_processed
.
with open("C:\Users\me\Documents\myfile.json") as fp:
data_processed = json.load(fp)
I have a .json file with keys such as “URL”, “text” (which is very long), “abstract”, “author”, “image” etc. I want to construct an HTML table in Python with all these values, except for the text. I tried it with json2html in these two ways (it worked only for very small examples):
import json
data_processed = json.loads('C:\Users\me\Documents\myfile.json')
formatted_table = json2html.convert(json = data_processed)
But it throws the error:
JSONDecodeError Traceback (most recent call last)
<ipython-input-15-b8f0fd5ea78d> in <module>
1 import json
----> 2 data_processed = json.loads('C:\Users\me\Documents\myfile.json')
3 formatted_table = json2html.convert(json = data_processed)
~Anaconda3libjson__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
346 parse_int is None and parse_float is None and
347 parse_constant is None and object_pairs_hook is None and not kw):
--> 348 return _default_decoder.decode(s)
349 if cls is None:
350 cls = JSONDecoder
~Anaconda3libjsondecoder.py in decode(self, s, _w)
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
339 if end != len(s):
~Anaconda3libjsondecoder.py in raw_decode(self, s, idx)
353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The other way was:
from json2html import *
input2 = {
"name": "something",
"description": "some description"
}
json2html.convert(json = input2)
But I don’t know how to import my file instead of this dictionary.
You are trying to parse the filename as the JSON.
Thank you, it worked! Is it possible to delete the “text” column when generating the table? I knew it was possible with OpenJSON in SQL Server, but how does it work in Python?
To delete the column you can just delete the key text for all elements, by doing something like this