JSON Schema support in Webstorm 2016.1

"What's New In Webstorm 2016.1" for says coding assistance is available for JSON files associated with a schema, and that "You can add one of the available schemas, or create your own schema and then map it to a specific JSON file in your project."

However it's not clear how to map schemas to JSON files or enable coding assitance in the editor.  

Specifically, I have a .json file in my project and a schema.json file that is available locally in the same project and at a public url, and I would like to associate the .json file with the schema and enable coding support and validation in the editor.  How do I do this?

I have found nothing in the preferences, app menus or context menus relating to this at all.

Any help would be appreciated

 

6 comments
Official comment

Hello Mashaal, you are right. The problem is we are using now code assistance based on the schema

http://json-schema.org/draft-04/schema#

itself, which is not very detailed. I created an issue so that it will be better tracked: https://youtrack.jetbrains.com/issue/WEB-22082

JSON schemes and mappings can be added in Settings (Preferences) | Languages & Frameworks | JSON Schema. Please see https://www.jetbrains.com/help/webstorm/2016.1/json-schema.html?page=1

0

I have mapped my JSON files to the JSON Schemas in my project. I can use autocomplete in my JSON files. How can I validate my JSON files using schemas? I have wrote wrong node in my JSON but I cannot see any errors. Should I use "Inspect code..." option? It would be very helpful to have an error indication "on type". Thanks.

0

JSON files are validated against schemas, errors are shown directly in the editor as inspections warnings - for example, you will see errors if required properties are missing, incorrect types being used, etc. But it doesn't give any errors on 'unknown' properties - this has been done at users requests

0

Yes, I see errors as a colored strips. Thanks.

0

I am getting certain errors but not others. For instance, I am building a json schema and validating against the json schema's main schema found at:

http://json-schema.org/draft-04/schema#

 Inside this schema, for instance, for the "required" property under a type defined under "definitions", there is a reference to "stringArray". However if I do not use a "stringArray" format for the value of the "required" property for my defined type, the JSON schema validation does not give me an error where it should. This is invalid but gives no error:

{
"$schema": "http://mydomain.com/WebScraperCrawl#",
"id": "http://mydomain.com/WebScraperCrawl#",
"blah": "blah",
"definitions": {
"crawlStepType": {
"type": "string",
"enum": [
"C",
"P",
"I"
],
"required": "type"
}
}
}

This gives no error (as it should). Notice the square brackets added:

 

{
"$schema": "http://mydomain.com/WebScraperCrawl#",
"id": "http://mydomain.com/WebScraperCrawl#",
"blah": "blah",
"definitions": {
"crawlStepType": {
"type": "string",
"enum": [
"C",
"P",
"I"
],
"required": ["type"]
}
}
}

Which brings to question, is type validation happening as it should be? If I am doing something wrong on my side, please advise.

Note: When I used http://www.jsoneditoronline.org/ for the same task, with the appropriate json schema set, and the expected validation comes up. This tool/site may be a good test bench for this test case (and others).

0

Please sign in to leave a comment.