AykutSarac / jsoncrack.com

✨ Innovative and open-source visualization application that transforms various data formats, such as JSON, YAML, XML, CSV and more, into interactive graphs.
https://jsoncrack.com/
Other
33.5k stars 2.15k forks source link

[BUG]: JSON Crack refuses to process documents with unresolved $schema #311

Closed joooeey closed 1 year ago

joooeey commented 1 year ago

Issue description

Example code:

{
  "$schema": "tag:example.com,2023",
  "squadName": "Super hero squad",
  "homeTown": "Metro Town"
}

In VS code I get the problem "Unable to load schema from 'tag:example.com,2023' [...]". And no output is shown. I think this treatment is incorrect because:

  1. The $schema property has no standardized meaning in normal JSON data documents. The key is like any other string. JSON-schema in particular is not part of the JSON standard.
  2. The $schema property in JSON-schema documents is supposed to identify the URI of the meta schema used for validating the schema. However,
    • I didn't specify that this is a schema. The non-toy example that had this problem actually isn't a meta-schema but a normal data document. Even in JSON-schema, $schema has no defined meaning in data documents. I went with the convention of using $schema to identify the schema that applies.
    • The $schema URI doesn't have to be resolvable according to the JSON-schema spec. This is crucial because it looks like at least the web editor can't resolve any schema from the WWW (tested with "$schema": "https://geojson.org/schema/Geometry.json but not in VS Code).
      1. I don't see the rationale for not visualizing JSONs that are invalid according to the schema implied by the unofficial $schema property. A warning that the file doesn't fit the schema should be enough. Or in this case a warning that the schema couldn't be resolved.

Media & Screenshots

No response

Operating system

Platform-independent. (jsoncrack.com/editor and VS Code, Linux and Windows)

Priority this issue should have

Low (slightly annoying)

joooeey commented 1 year ago

I'd like to point out that the current behavior is still technically incorrect. The GUI at jsoncrack.com/editor mentions an "Invalid Format". However, the format given in the example may be perfectly valid. Specifically, JSON-Crack doesn't know the schema that's allegedly defined at tag:example.com,2023, so it can't say whether the JSON is valid or not. Furthermore, the $schema property does not need to be resolvable.

This issue is now a lot more minor than what I originally reported. The important thing is that I can see the visualization now. Great work!

Screenshot_2023-08-23_09-55-05