Code Monkey home page Code Monkey logo

Comments (8)

gkellogg avatar gkellogg commented on June 17, 2024

While reading w3c/pub-manifest#65 I tested the following JSON-LD in the playground:

{
  "@context": {
    "name": {
      "@id": "http://example.com/name",
      "@type": "xsd:string"
    }
  },
  "name": true
}

This resulted in this unexpected (by me) expanded form:

[
  {
    "http://example.com/name": [
      {
        "@type": "xsd:string",
        "@value": true
      }
    ]
  }
]

Obviously...that's incorrect and I'd expected a warning, error, or (perhaps) type coercion.

Not incorrect, but are you suggesting that we should build in knowledge of the "xsd" so we know that it's not intended as an IRI scheme?

Reshaping it a bit, I added a @language tag, and that did throw a more expected error:

{
  "@context": {
    "name": {
      "@id": "http://example.com/name",
      "@type": "xsd:string"
    }
  },
  "name": {
    "@language": "en",
    "@value": true
  }
}

Ask here is to see if we could make this more obvious. 😄

The purpose of the @type in the term definition is to know how to interpret string values. In this case, it's a value object, so the @type definition does not come into play.

from json-ld-bp.

gkellogg avatar gkellogg commented on June 17, 2024

(Sorry, this isn't about the xsd prefix, but about the asymmetry of handling value coercion).

Typically, if we see values that are native JSON values (true, ...), the algorithms just leave them alone. If we were not to assign the @type to the value object, we would be out-of-spec with 1.0, which is explicit about doing this.

Perhaps adding something that would make a native value along with @type in a value object, or in coercion, an error, we could get away with it, but again are in danger of invalidating JSON-LD 1.0 content.

from json-ld-bp.

BigBlueHat avatar BigBlueHat commented on June 17, 2024

So, I'm probably wanting the xsd:string (and friends) to be more "magic" than it is currently. And perhaps it's not JSON-LD's job to verify data--just to expand it.

The thinking is that the following expanded form JSON would be considered invalid by any one implementing a spec or code--see w3c/pub-manifest#65 for a specific scenario and discussion:

[
  {
    "http://example.com/name": [
      {
        "@type": "xsd:string",
        "@value": true
      }
    ]
  }
]

The result of the lack of this in JSON-LD means that something else (often JSON Schema) is needed to do actual value/content validation. Is/was that the expected scenario? If that's the case, then explaining this is certainly needed for the Best Practices. /cc @ajs6f

Also, I'm guessing the xsd: prefix is the only one of it's kind?--i.e. CURIE's that don't expand?

from json-ld-bp.

iherman avatar iherman commented on June 17, 2024

This issue was discussed in a meeting.

  • RESOLVED: Transfer w3c/json-ld-syntax#257 to best practices document
View the transcript Rob Sanderson: Moving on to #257…
Ivan Herman: See issue syntax#257
Benjamin Young: It’s probably reducible to an editorial thing in a best practices document.
… People are going to get confused when they do type coercion and they’re getting booleans that are typed as xsd:datetime… I’d love to see, when we recharter to fix bugs, I don’t expect this is a JSON-LD proper problem… I’d like an extra spec that goes and checks these things.
Gregg Kellogg: If you run it through a linter…
Benjamin Young: This is an acceptable way to do it via our specs, it looks wrong, but validation is not JSON-LD’s problem, but we didn’t take that on.
Ivan Herman: RDF doesn’t do those things either, you can have values w/ datatypes, which is wrong.
Benjamin Young: so, you can say it’s best practices stuff
… The CG could address this, these are the kinds of things that we need to address w/ the community
Gregg Kellogg: A different example, instead of a string it’s an xsd:datetime, that’s valid -
Benjamin Young: When people have an expectation of JSON-LD, and it’s one thing, and it turns out to not be that one thing… we need to build bridges towards validation.
Rob Sanderson: If you push this through to RDF, you’ll get the right thing back out.
Gregg Kellogg: well, if it’s xsd:string, you will get that, but if it’s “boolean” you will.
… another thing that could happen, is when you expand, ignored if it’s an array or object… it could be ignored for numbers… you don’t know, could be decimal/double.
Pierre-Antoine Champin: JSON-LD has support for more datatypes than RDF… it’s better, the fact that it doesn’t support other datatypes can be argued by the fact that it’s open… xsd:datatypes…
Rob Sanderson: We should transfer this issue to best practices…
Benjamin Young: my confusion is about expanded form vs. compact
… if name had ex: in front of it, it wouldn’t show up…
Gregg Kellogg: no, it would show up, it’s an IRI
Proposed resolution: Transfer w3c/json-ld-syntax#257 to best practices document (Rob Sanderson)
Rob Sanderson: +1
Gregg Kellogg: +1
Benjamin Young: +1
Simon Steyskal: +1
Manu Sporny: +1
Pierre-Antoine Champin: +1
Ivan Herman: +1
Resolution #7: Transfer w3c/json-ld-syntax#257 to best practices document
Benjamin Young: if if if if if
Benjamin Young: {"name": true}
Benjamin Young: That doesn’t survive
Gregg Kellogg: The later one isn’t absolute IRI… the previous is
… This might be why manu keeps saying compact IRIs were a mistake
Benjamin Young: It means you have a bit of a rosetta stone w/ @context.
Rob Sanderson: That’s all of the open issues, except for the loads of editorial issues.
… The framing stuff has no more issues either.

from json-ld-bp.

ajs6f avatar ajs6f commented on June 17, 2024

I think we can address this, but IIUC I'm not sure we need to say much more than "JSON-LD contains no internal mechanism for data validation. You have to supply that yourself." (modulo better wording)

Or @BigBlueHat , are you thinking of a core commitment we could be seen as letting down?

from json-ld-bp.

BigBlueHat avatar BigBlueHat commented on June 17, 2024

Or @BigBlueHat , are you thinking of a core commitment we could be seen as letting down?

Not a core commitment, but a frequently misplaced expectation. 😕 We can certainly call it out with something as simple as you describe, so I'll take a crack at that shortly.

from json-ld-bp.

azaroth42 avatar azaroth42 commented on June 17, 2024
  • You can't create new rdf:type triples by setting @type in the context. Use Framing and @default (note that 1.0 did not allow @default for @type)
  • Core purpose is context for the JSON to interpret it -- especially how you interpret strings.
  • Native values + type coercion: No need to coerce native types, because they're not strings.

from json-ld-bp.

iherman avatar iherman commented on June 17, 2024

This issue was discussed in a meeting.

  • No actions or resolutions
View the transcript Typing gotchas
Rob Sanderson: #14
Rob Sanderson: @type sometimes does not behave as anticipated, even by bigbluehat
… how can we describe it in the BP document, so that people understand the intent of @type
… The process proposed last week was to go through issues, discuss what we want to say,
… and have someone write it properly.
Pierre-Antoine Champin: Type coercion is only for strings. Native types do not need coercion, and are hence insensitive to this
Rob Sanderson: would the BP entry be about type coercion, or about the interaction thereof with native types?
… the gotchas for type coercion seems to be about creating “rdf:type” triples
… (or rather not being able to do it)
… has anyone tried to explain that?
Gregg Kellogg: the core purpose of JSON-LD is to provide context, helping to interpret JSON,
… especially how to interpret strings in that JSON.
… It might intersect with “type-coercion with native value”,
… as some people are wanting to add triples to an object.
… Adding triples is the job of framing.
Rob Sanderson: and we fixed @default in framing, when applied to @type.
… Do we have an issue for that in the BP,
… we cause indeed we run into that issue a lot?
… points to consider
You can’t create new rdf:type triples by setting @type in the context. Use Framing and @default (note that 1.0 did not allow @default for @type)
Core purpose is context for the JSON to interpret it – especially how you interpret strings.
Native values + type coercion: No need to coerce native types, because they’re not strings.

from json-ld-bp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.