How to import JSON dataset with references?

How do I import large JSON datasets that reference objects via a unique identifier other than Dgraphs uid?

Let’s say I have multiple employees that work_for a company ABC:

{
  "name": "Alice",
  "works_for": "ABC"
},
{
  "name": "Bob",
  "works_for": "ABC"
}
...
{
  "name": "ABC",
  "is_company": "true"
}

Neither this, nor

{
  "name": "Alice",
  "works_for": {
    "name": "ABC",
    "is_company": "true"
  }
},
{
  "name": "Bob",
  "works_for": {
    "name": "ABC",
    "is_company": "true"
  }
}
...

Will give me the correct result (i.e. both edges pointing to the same node/uid).

I hope there is a way to resolve this via some id function or something?

Use Blank Nodes identifier https://docs.dgraph.io/mutations/#edges-between-nodes

In the tour there’s an example for this in JSON answer https://tour.dgraph.io/schema/2/

In https://tour.dgraph.io/intro/4/ you have another similar example.

Thanks, I wasn’t aware that blank identifiers also work in JSON :+1:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.