本文介绍了使用tidyjson将JSON文件转换为Dataframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Mongodb以以下格式导出了JSON文件.我正在尝试从中创建一个数据框,但看不到tidyjson来读取它,因为它会引发此错误.

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) ------^

我使用了read_json("file.json")

I used read_json("file.json")

文件在下面

{
    "_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")
        }
    ]
}

推荐答案

由于mnogodb产生的这种错误会产生扩展的" json格式.您应该尝试使用"mongoexport( https://docs.mongodb.com/manual/reference/mongodb-extended-json/)

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/)

这篇关于使用tidyjson将JSON文件转换为Dataframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 06:48