Hamid Javid Hamid Javid - 2 months ago 6
Javascript Question

json array with in array returning error ?bad string

i am parsing my json string file to python and always returning error .
i used online json formatter and validators that also returning error so i want help to make my json correct and tell me error

[{
"sentence_id": "TR.00001",
"sentence": {

"text": "Bill was born 1986.",
"annotation": {
(1, "Bill", "bill", "NNP", "B-PERSON"),
(2, "was", "be", "VBD", "O"),
(3, "born", "bear", "VBN", "O"),
(4, "1986", "BIL", "CD", "B-DATE"),
(5, ".", ".", ".", "O"),

},
"relations": {
"subject": "bill",
"predicate": "DATE of Birth",
"object": "1986"
}
}
}, ]


the above is my json string you can check online validators or online json format verifier here is the part of json that returns error

"annotation": {
(1, "Bill", "bill", "NNP", "B-PERSON"),
(2, "was", "be", "VBD", "O"),
(3, "born", "bear", "VBN", "O"),
(4, "1986", "BIL", "CD", "B-DATE"),
(5, ".", ".", ".", "O"),
},


so can you please help me in sorting out the trouble of array with in array using json you can use these editors link link to json editor


expecting property name
,
error in line 8

Answer

JSON doesn't understand tuples, try changing to lists:

"annotation": [
    [1, "Bill", "bill", "NNP", "B-PERSON"],
    [2, "was", "be", "VBD", "O"],
    [3, "born", "bear", "VBN", "O"],
    [4, "1986", "BIL", "CD", "B-DATE"],
    [5, ".", ".", ".", "O"]
]

You can do tuple(list) to convert back to tuples on the other end.

Also, you had an extra comma on [5, ".", ".", ".", "O"], I removed it.