w3c / json-ld-framing

JSON-LD 1.1 Framing Specification
https://w3c.github.io/json-ld-framing/
Other
25 stars 20 forks source link

Remove @omitDefault? #41

Closed gkellogg closed 5 years ago

gkellogg commented 5 years ago

The @omitDefault flag can be added to a frame to change the default value for the omit default flag, which might be set to true through an API call. This keyword is of dubious value, since the frame can simply add @default at all.

Propose removing the keyword. We may also want to consider how important the runtime flag is.

dlongley commented 5 years ago

I think the @omitDefault flag was added to enable the granular prevention of properties (that need to have other flags set on them) from appearing in the output when they aren't present in the data.

An example is here: https://github.com/digitalbazaar/jsonld.js/issues/117

Though, sadly, the playground example is now partially broken because the user's context went away. But the basic idea there was that some property needed to be marked with "@embed": "@never" but, if that property was not present in the data, it needed to be omitted entirely in the output... regardless of whether default values were permitted elsewhere.

iherman commented 5 years ago

This issue was discussed in a meeting.

dlongley commented 5 years ago

Here's an example of where @omitDefault is useful:

Suppose the following input:

{
  "@context": {
    "@vocab": "http://example.org/",
    "child": {"@type": "@id"}
  },
  "@graph": [
    {
      "@id": "http://example.org#John",
      "@type": "Person",
      "name": "John",
      "child": "http://example.org#Jane"
    },
    {
      "@id": "http://example.org#Jane",
      "@type": "Person",
      "name": "Jane"
    }
  ]
}

Suppose this frame (that does not have @omitDefault):

{
  "@context": {
    "@vocab": "http://example.org/",
    "child": {"@type": "@id"}
  },
  "@type": "Person",
  "child": {
    "@embed": "@always"
  }
}

This is the framed output:

{
  "@context": {
    "@vocab": "http://example.org/",
    "child": {
      "@type": "@id"
    }
  },
  "@graph": [
    {
      "@id": "http://example.org#Jane",
      "@type": "Person",
      "child": null,
      "name": "Jane"
    },
    {
      "@id": "http://example.org#John",
      "@type": "Person",
      "child": {
        "@id": "http://example.org#Jane",
        "@type": "Person",
        "name": "Jane"
      },
      "name": "John"
    }
  ]
}

Note that because the option "@embed": "@always" is specified in the frame under the child property, that "child": null appears in the output for matches that do not have that property. This may be undesirable. To prevent this default null output from occurring, the @omitDefault may be set to true like so:

{
  "@context": {
    "@vocab": "http://example.org/",
    "child": {"@type": "@id"}
  },
  "@type": "Person",
  "child": {
    "@embed": "@always",
    "@omitDefault": true
  }
}

Which yields this (desirable) output:

{
  "@context": {
    "@vocab": "http://example.org/",
    "child": {
      "@type": "@id"
    }
  },
  "@graph": [
    {
      "@id": "http://example.org#Jane",
      "@type": "Person",
      "name": "Jane"
    },
    {
      "@id": "http://example.org#John",
      "@type": "Person",
      "child": {
        "@id": "http://example.org#Jane",
        "@type": "Person",
        "name": "Jane"
      },
      "name": "John"
    }
  ]
}