0

When i import json data after deleting the ids, my import function works properly. However, if i import the data with my own id, console shows data is undefined.

    [
    {
    "data" : "abc",
    "parent" : null,
    "type" : "Organization",
    "parentType" : null,
    "API" : "",
    "value" : "abc",
    "filename" : "uploads.wsdl",
    "company" : "comapany"
    },
    {
    "data" : "def",
    "parent" : "abc",
    "type" : "Department",
    "parentType" : "Organization",
    "API" : "",
    "value" : "def",
    "filename" : "uploads.wsdl",
    "company" : "company"
    }
    ]

        d3.json("marvel.json", function(error, mydata) {
    console.log(mydata)
    });

The above code works fine.

    [
    {
    "_id" : ObjectId("5d2d862a68a6bc22a9e99046"),
    "data" : "abc",
    "parent" : null,
    "type" : "Organization",
    "parentType" : null,
    "API" : "",
    "value" : "abc",
    "filename" : "uploads.wsdl",
    "company" : "company"
    },
    {
    "_id" : ObjectId("5d2d862a68a6bc22a9e99047"),
    "data" : "def",
    "parent" : "abc",
    "type" : "Department",
    "parentType" : "Organization",
    "API" : "",
    "value" : "def",
    "filename" : "uploads.wsdl",
    "company" : "comapny"
    }
    ]
        d3.json("marvel.json", function(error, mydata) {
    console.log(mydata)
    });

In this code mydata is undefined

  • 1
    That's because your JSON is invalid, you can't have `"_id" : ObjectId("5d2d862a68a6bc22a9e99046")`. Since I don't know if you're using Python/Mongo/Flask I'll not close this question now, but I advise you to have a look here: https://stackoverflow.com/q/16586180/5768908 – Gerardo Furtado Jul 17 '19 at 03:29

1 Answers1

-1

This:

{"_id" : ObjectId("5d2d862a68a6bc22a9e99047")}

Is not valid JSON, Function calls or object initialization isn't part of the JSON spec and fails will fail under any sane JSON parser.

Ryan Jenkins
  • 878
  • 8
  • 16