json-ld / json-ld.org

JSON for Linked Data's documentation and playground site
https://json-ld.org/
Other
856 stars 152 forks source link

compacting nested values #718

Open LucaCerina opened 4 years ago

LucaCerina commented 4 years ago

Hello, considering an expanded json-ld in the form

"http://example.com/vocab/wake": [
  {
    "http://example.com/vocab/minutes": [
      {
        "@value": 15
      }
    ]
  }
]

what should I have in the compaction context to have something like:

"wake" : 15

thanks for the help

gkellogg commented 4 years ago

Can't do that, I'm afraid. You can use Property Nesting to expand to that form, more or less.

{
  "@context": {
    "@vocab": "http://example.org/",
    "minutes": {"@nest": "wake"},
    "wake": "@nest"
  },
  "wake": {
    "minutes": 15
  }
}

Expands to:

[
  {
    "http://example.org/minutes": [
      {
        "@value": 15
      }
    ]
  }
]