Validate JSON document against schema

When loading a JSON representation of a document into the ProseMirror editor my experience has been that the rendering will fail silently if the JSON document does not conform to the schema. This results in a lot of wasted time manually validating documents against schema. Is there now, or could there be, some function that will validate a JSON doc against a schema spec? Ideally any point where validation failed would be reported to the caller. This would make it dramatically easier to build applications that store ProseMirror documents in JSON.

Ed

1 Like

Yes, there is.

1 Like

Thanks Marijn,

Sorry, I was looking under Schema for the function rather than Node. I’ll start calling check() on my doc before loading.

Ed

This appears outdated?

// "prosemirror-model": "1.8.2"
// 
try {
        let doc = this.editor.createDocument(content)
        doc.check()
        console.log(this.editor, content, doc)
        /*vm.identityService.send(
          SET_DOC, { doc: doc.toJSON() }
        )*/
   } catch (e) {
        console.log(e)
   }

All I get is the console warning. Check returns undefined either way.

How do i validate with an schema or editor context?