I would like to insert a json containing several publications in my database. I want to create a field for each publication. For the moment I managed to insert a json containing a single publication, however when I try with two, it makes me a mistake:
Script python :
fichier = open("result2.json","r")
filedata = json.load(fichier)
#for '{' in filedata:
#print "ici un {"
prod = Production()
prod.cle = filedata.get("UT")
prod.titre = filedata.get("TITRE")
prod.publis = filedata
prod.maj = timezone.now()
prod.save()
fichier.close()
result2.json
{
"UT": "WOS:123456",
"TI": "firstpubli",
"DT": "journal",
"PY": "2016",
"TITRE" :"firstpubli2016",
"AU": "me, you"
}
What does it do [enter image description here][1]
Now if I put 2 publications in result2.json:
{
"UT": "WOS:123456",
"TI": "firstpubli",
"DT": "journal",
"PY": "2016",
"TITRE" :"firstpubli2016",
"AU": "me, you"
}
{
"UT": "WOS:78910",
"TI": "secondpubli",
"DT": "journal",
"PY": "2016",
"TITRE" :"secondpubli2016",
"AU": "me, you"
}
When I run the python script to insert the data, I have this error
Traceback (most recent call last):
File "test.py", line 45, in <module>
filedata = json.load(fichier)
File "/usr/lib/python2.7/json/__init__.py", line 291, in load
**kw)
File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 367, in decode
raise ValueError(errmsg("Extra data", s, end, len(s)))
ValueError: Extra data: line 12 column 2 - line 21 column 1 (char 143 - 282)
And nothing is inserted in the database My goal is to get like on this image, 2 productions, when I have 2 productions in my json enter image description here
} , {and so on?