Search code examples
rdfjson-ld

Convert between JSONLD serialization forms


I have the JSONLD data (about 5 GiB) in the following form:

[{
    "@id": "_:node1derd3aqnx968310",
    "http://www.example.org/uri-for/preferredName": [{
        "@value": "Doe, John"
      }
    ]
  }, {
    "@id": "http://www.example.org/myres012345",
    "@type": ["http://www.example.org/uri-for/person"],
    "https://schema.org/additionalName": [{
        "@id": "_:node1derd3aqnx968310"
      }
    ]
  }
]

And what I want is:

[{
    "@id": "http://www.example.org/myres012345",
    "@type": ["http://www.example.org/uri-for/person"],
    "https://schema.org/additionalName": [{
        "http://www.example.org/uri-for/preferredName": [{
            "@value": "Doe, John"
          }
        ]
      }
    ]
  }
]

How's are these different serialization forms called? How can I convert the first (flat) JSONLD to the hierarchical JSONLD in the second example? Can someone recommend a Java library or something similar?

That's for your help, folks!


Solution

  • I think you're asking for JSON-LD Framing. Like in this example.

    Framing is used to shape the data in a JSON-LD document, using an example frame document which is used to both match the flattened data and show an example of how the resulting data should be shaped. Matching is performed by using properties present in in the frame to find objects in the data that share common values. Matching can be done either using all properties present in the frame, or any property in the frame. By chaining together objects using matched property values, objects can be embedded within one another.

    Use the example link above to play around with the example and to get a feeling on how the frame document works.