'Get list of current schema validation errors from Monaco with JSON schema

I have a Monaco editor setup similar to the example one on the playground: https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-configure-json-defaults

I would like to get a list of the current schema validation warnings so I can show them to the user in a list in my UI. (ie. get a list of all the locations and the text similar to what you see when you hover over the highlighted warnings in the example above).

Is there an API with Monaco to get a list of all the current validation errors/warnings?



Solution 1:[1]

As pointed out in the comments, validation errors and warnings in Monaco editor are stored as IMarkers.
To get a list of these markers, there is a method getModelMarkers(), that returns the list of all markers from a given owner.
Usually, for validation errors and warnings from a language, the owner is the id of the said language, "json" in your case.

So, to get validation errors and warnings from JSON schema, this will get the job done:

var markers = Monaco.editor.getModelMarkers({owner: "json"});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Astor Bizard