DeepBlueCLtd / json-schema-editor

JSON Editor focussed on developing/editing JSON Schema documents
https://deepbluecltd.github.io/json-schema-editor/
GNU General Public License v3.0
9 stars 2 forks source link

Derive JSON Schema from document sample (Defer) #10

Open IanMayo opened 5 years ago

IanMayo commented 5 years ago

@pmk65 made the great suggestion that the schema editor should be able to infer the schema from a sample document.

In the JSON-Editor context, "Update Form" populates the editor with the JSON document.

So, in this JSON-Schema-Editor context, it's a JSON Schema document that would be pasted into the "Output" text-area, and then the editor gets updated with that schema.

What @pmk65 is describing is a logical step further. He's describing a JSON document being pasted into a new text-area, then an algorithm parses the document to derive a JSON schema, then paste that content into the Output window, then re-populate the editor with the content of that schema.

I recognise the value in that process, but deriving the schema from the document is a step that's not currently perform in JSON-Editor (note - I think I've found JS code to do it here [1]).

It's a stretch target, but it's a great target to aim for :-)

[1]. https://github.com/DeepBlueCLtd/json-schema-editor/issues/9#issuecomment-467440138

Franciman commented 5 years ago

https://github.com/niebert/JSON2Schema This project does seem to do the same, we may use it to generate the schema from a json value.

joshuafontany commented 5 years ago

I considered that one as well, but ended up using https://github.com/ruzicka/to-json-schema

Franciman commented 5 years ago

Thanks @joshuafontany, do you have it implemented in your TiddlyWiki demo, too?

joshuafontany commented 5 years ago

Yes. Go to any Json Tiddler, or create a new tiddler and paste Json text into the body field. Set the type to 'application/json', and new UI will render, one of which is a Create Schema button. That will auto-generate a separate schema tiddler (and set a reference on the source tiddler) and open it in the story-river.