
Hello,
That is correct, we don't have anything at the moment built-in for JSON validation. As far as I know, JSON validation isn't in .NET and is only in third-party libraries like Newtonsoft's Json.NET, right?
That being said, our syntax languages are fully extensible and you can add this kind of thing if you wish.
In our XML add-on, we override our XmlParser's CreateParseData method and call a Validate method in that, passing it the request and state parameters. You could do the same kind of thing by making a class that inherits JsonParser, and override CreateParseData to call a Validate method you add, then call the base CreateParseData method. Unregister our default JsonParser service from the language and register an instance of your custom JsonParser-based class instead.
Here's what our XmlParser.Validate method looks like:
protected virtual void Validate(IParseRequest request, IParserState state) {
if (request == null)
throw new ArgumentNullException("request");
if (state == null)
throw new ArgumentNullException("state");
if ((request.TextBufferReader != null) && (request.Language != null)) {
// If there is a validator service on the language...
IXmlValidator validator = request.Language.GetService<IXmlValidator>();
if (validator != null) {
// Validate the XML
var ast = (state.AstNodeBuilder != null ? state.AstNodeBuilder.RootNode : null);
IEnumerable<IParseError> validationErrors = validator.Validate(request, ast);
if (validationErrors != null) {
// Add validation errors
foreach (IParseError validationError in validationErrors) {
if (validationError != null)
state.ReportError(validationError);
}
}
}
}
}
We effectively look for another language service of type IXmlValidator and if found call into it with the request and AST result. Then we take the IParseError results from that validation, and report them on the state object.
If you want to simplify things, instead of calling another validator language service, you could validate using Json.NET right from this Validate method. The request.TextBufferReader will give you access to the snapshot's raw text. Then report the errors that were found.
I hope that helps!