1

I exported a JSON file from Mongodb with the below format. I'm trying to create a dataframe from it but I can't see to get tidyjson to read it as it throws this error.

Error: lexical error: invalid char in json text.
                        {      "_id" : ObjectId("586e684427a06a4a658fa
                     (right here) ------^

I used read_json("file.json")

The file is below

{ 
    "_id" : ObjectId("586e684427a06a4a658fa28e"), 
    "expires_in" : ISODate("2016-11-19T22:16:57.418+0000"), 
    "job_type" : "Satellite Sales & Service", 
    "inbound_id" : ObjectId("586e68440c83945fb2658754"), 
    "created_at" : ISODate("2017-01-05T15:37:40.850+0000"), 
    "action_states" : [
        {
            "_id" : ObjectId("586e684627a06a4a658fa293"), 
            "transition_duration" : NumberInt(0), 
            "name" : Symbol("created"), 
            "actor" : "home_owner", 
            "created_at" : ISODate("2017-01-05T15:37:42.297+0000")
        }, 
        {
            "_id" : ObjectId("586e68ad0c83945fb2658825"), 
            "transition_duration" : NumberInt(1), 
            "name" : Symbol("accepted"), 
            "reason" : null, 
            "actor" : "contractor", 
            "created_at" : ISODate("2017-01-05T15:39:25.924+0000")
        }
    ]
}
{ 
    "_id" : ObjectId("586e675d27a06a4a658fa264"), 
    "expires_in" : ISODate("2016-11-19T22:16:57.418+0000"), 
    "job_type" : "Satellite Sales & Service", 
    "inbound_id" : ObjectId("586e675d0c83945fa2f6e190"), 
    "created_at" : ISODate("2017-01-05T15:33:49.934+0000"), 
    "action_states" : [
        {
            "_id" : ObjectId("586e675f27a06a4a658fa267"), 
            "transition_duration" : NumberInt(0), 
            "name" : Symbol("created"), 
            "actor" : "home_owner", 
            "created_at" : ISODate("2017-01-05T15:33:51.097+0000")
        }, 
        {
            "_id" : ObjectId("586e694c0c83945faae36559"), 
            "transition_duration" : NumberInt(8), 
            "name" : Symbol("accepted"), 
            "reason" : null, 
            "actor" : "contractor", 
            "created_at" : ISODate("2017-01-05T15:42:04.116+0000")
        }
    ]
}

1 Answer 1

3

This error due to mnogodb produce "extended" json format. You should try to export your data in 'strict' json mode using, for example, mongoexport (https://docs.mongodb.com/manual/reference/mongodb-extended-json/)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.