Reputation: 2876
I have a custom platform where I upload files. The platform get the content of the files (mapping) and then I have a screen where I can see the content.
My problem is with a specific JSON file. This is the original format :
{"schema:actor:image":"https://LINK.png","schema:activity.timestamp:timestamp":"01/06/2016 19:23:01","schema:metadata:datatype":"text","schema:actor:name":"AAAA","schema:metadata.tags:key":null,"schema:activity.content:value":"VALUE1","schema:activity.content:language":["english"],"schema:activity.location:placename":"City of London, United Kingdom","schema:actor:followers_count":1518,"schema:activity.content:sentiment":"positive","schema:activity.content:opinion":"neutral","schema:activity.content:gender":"unknown","schema:activity.content:age":"35-49","schema:actor:synthetic":"no","schema:activity:original_post":null,"streams":["Apollo"]} {"schema:actor:image":"https://LINK2.jpg","schema:activity.timestamp:timestamp":"02/06/2016 23:16:39","schema:metadata:datatype":"text","schema:actor:name":"BBBB","schema:metadata.tags:key":null,"schema:activity.content:value":"VALUE2","schema:activity.content:language":["english"],"schema:activity.location:placename":"Birmingham, United Kingdom","schema:actor:followers_count":28,"schema:activity.content:sentiment":"neutral","schema:activity.content:opinion":"subjective","schema:activity.content:gender":"unknown","schema:activity.content:age":"25-34","schema:actor:synthetic":"no","schema:activity:original_post":"738022479273454944","streams":["Apollo"]}
And I cannot use this file on the platform. The only way to make it work is to alter the format a bit. This format works :
[{"schema:actor:image":"https://LINK.png","schema:activity.timestamp:timestamp":"01/06/2016 19:23:01","schema:metadata:datatype":"text","schema:actor:name":"AAAA","schema:metadata.tags:key":null,"schema:activity.content:value":"VALUE1","schema:activity.content:language":["english"],"schema:activity.location:placename":"City of London, United Kingdom","schema:actor:followers_count":1518,"schema:activity.content:sentiment":"positive","schema:activity.content:opinion":"neutral","schema:activity.content:gender":"unknown","schema:activity.content:age":"35-49","schema:actor:synthetic":"no","schema:activity:original_post":null,"streams":["Apollo"]},
{"schema:actor:image":"https://LINK2.jpg","schema:activity.timestamp:timestamp":"02/06/2016 23:16:39","schema:metadata:datatype":"text","schema:actor:name":"BBBB","schema:metadata.tags:key":null,"schema:activity.content:value":"VALUE2","schema:activity.content:language":["english"],"schema:activity.location:placename":"Birmingham, United Kingdom","schema:actor:followers_count":28,"schema:activity.content:sentiment":"neutral","schema:activity.content:opinion":"subjective","schema:activity.content:gender":"unknown","schema:activity.content:age":"25-34","schema:actor:synthetic":"no","schema:activity:original_post":"738022479273454944","streams":["Apollo"]}]
The difference in a picture is here (additions are in red color) :
Is there a way to read the first file using JSONpath? I am not familiar with JSONpath and I was not able to read the first file.
Alternatively, I am thinking of manipulating the file in order to add the missing parts --> to make it look like the 2nd file.
Upvotes: 0
Views: 248
Reputation: 2523
The problem with your first JSON is that you are passing several objects {} separated by commas, but you're not enclosing into another object or an array [].
{},{},{} === bad formed JSON, three orphan objects
{ "obj1": {}, "obj2": {}, "obj3": {} } === good JSON, one object that encloses three other objects into it's attributes
[ {}, {}, {} ] === good JSON, an array of JSON objects.
Upvotes: 2