Skip to content

Flatten original JSON hierarchy? #385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MidnightLightning opened this issue Mar 16, 2015 · 2 comments
Closed

Flatten original JSON hierarchy? #385

MidnightLightning opened this issue Mar 16, 2015 · 2 comments

Comments

@MidnightLightning
Copy link

Somewhat related to cases #271 and #267, but both are a few years old, so wanted to re-clarify and see if there is a newer answer:

In attempting to provide @context to a JSON structure I don't own, I'm running into the issue of being unable to flatten the source structure, without adding the @context definitions into the JSON structure. The source data looks like:

{
  "version":"0.0.1",
  "header":{"datastore":"namecoin"},
  "data":{
    "name":"u/midnight",
    "value":{
      "website":"http://midnightdesign.ws",
      "bio":"Teaching computers / to make art with just some code. / It is what I do.",
      "github":{
        "username":"MidnightLightning",
        "proof":{
          "url":"https://gist.github.com/MidnightLightning/bcfffdf02fde63e7f25a"
        }
      },
      "name":{
        "formatted":"Brooks Boyd"
      },
      "twitter":{
        "username":"midnight426",
        "proof":{
          "url":"https://twitter.com/midnight426/status/486919185448972288"
        }
      },
      "next":"i/midnight-1"
    },
    "txid":"17fbf8cc44194703a7bddd736b49837e9e17298b2c17dc54dfc6fb848a3a62fe",
    "address":"N3XERXXsAEqmRAoyQpwtJqSAPPunWMMswT",
    "expires_in":11423
  }
}

(This is the JSON data stored in the Namecoin blockchain by the OneName identity service (example is the representation of my profile, which is stored on the Namecoin blockchain).

The issue is that the data is buried several layers deep, but really only refers to one entity. For example, to try and map myself to a Schema.org Person, with a Name and Website:

  "@context": {
    "schema": "http://schema.org/",
    "nc": "http://namecoin.com#",
    "data": "schema:person",
    "value": "nc:value",
    "name": "nc:name",
    "formatted": "schema:name",
    "website": {
      "@id": "schema:url",
      "@type": "@id"
    }
  }

That @context gets the values for "name" and "website" out, though it doesn't directly relate it to the "person" node, but rather to the "nc:value" -> "nc:name" middle nodes I have to put in there to make the "formatted" name show up.

Is there an existing way to flatten this hierarchy into one node worth of data? Or do I need to craft a pre-processor to restructure that data first? Or could using something like the Javascript dot-notation, with nested contexts be added to the spec to support this sort of thing:

  "@context": {
    "schema": "http://schema.org/",
    "nc": "http://namecoin.com#",
    "data": {
      "@id": "schema:person",
      "@context": {
        "name": {
          "@id": "nc:id",
          "@type": "@id"
        },
        "value.name.formatted": "schema:name",
        "value.website": {
          "@id": "schema:url",
          "@type": "@id"
        }
      }
    }
  }

With this structure, the parser could know that because "value.name.formatted" is defined in the root level of "data", it's a direct child of that node (which is a Person), rather than nodes in their own right? This would also solve the issue where "name" got doubled-up: data.name is an ID, while data.value.name is just a wrapper node, and this dot-notation allows separate contexts for them.

@gkellogg
Copy link
Member

This would be covered in #426.

@gkellogg gkellogg added this to the JSON-LD.next milestone Sep 22, 2016
@gkellogg gkellogg removed the 1.1 label Oct 6, 2016
@gkellogg
Copy link
Member

gkellogg commented Apr 8, 2017

Actually, this is now available using scoped contexts, merged in #445 and #462..

@gkellogg gkellogg closed this as completed Apr 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants