nickcmaynard / jsonschemalint

JSON Schema Lint. Like you I'm busy, so pull requests will get merged quicker than feature requests are implemented.
https://jsonschemalint.com
MIT License
80 stars 31 forks source link

Add YAML parsing/reformatting support and improve error value display #2

Closed jhford closed 9 years ago

jhford commented 9 years ago

Hi, thanks for the great tool. It's a really important part of my work flow. My project uses JSON schemas to validate all of our input, but is stored in YAML format. Since all JSON is valid YAML, it's a nice way to have comments and short schemas. I got sick of having to copy my schemas to a YAML->JSON converter, use this linter then convert back to YAML when I'm done. I used bower instead of browserify because I kept having an issue where yaml.js would overwrite isMyJsonValid's global which broke everything.

Anyway, here's a couple of patches which add YAML support. I opted to leave JSON.parse/stringify as the preferred option since YAML support shouldn't change anything about JSON. Basically, if something doesn't parse as JSON.parse friendly JSON, I try to use a YAML module to parse it.

The change about error messages is specifically because I'm sick to death of counting keys and seeing [Object object] in the error list.

Hope that these changes are merged, again thanks for the great tool.

nickcmaynard commented 9 years ago

Thanks for the sterling work, and for such a well explained PR.

Happy to merge this (and I'll rebuild jsonschemalint.com once it's done) after a couple of tweaks:

  1. I notice some is-my-json-valid changes - presumably due to an upstream change - can you lock down the version in bower.json, please?
  2. Spelling & grammar nazi changes - index.html change to read:

    <p>Optionally, you may use schemas and documents in the YAML format.  These documents are parsed with <a href="https://github.com/jeremyfa">Jérémy Fairve's</a> <a href="https://github.com/jeremyfa/yaml.js">yaml.js</a> library.</p>
  3. I'd suggest renaming parseThing and reformatThing to parseMarkup and reformatMarkup.
nickcmaynard commented 9 years ago

On second thoughts, is-my-json-valid is not in bower, of course. Any ideas on how to manage the version of this, given the build process?

jhford commented 9 years ago

Yes, it is an upstream change. I'm not sure which version of is-my-json-valid you're using on the site, but I reset the files to their current state with git reset upstream/master -- draft4/js/is-my-json-valid*. Since you're using grunt and browserify, which in turn is generating the is-my-json-valid module based on the contents of your npm managed copy of the module, you could probably figure out which version of is-my-json-valid using grep '"version":' node_modules/is-my-json-valid/package.json and then setting the jsonschemalint top level package.json file to have a non-~ version number.... i guess.... I'm not a browserify master, so that might be totally wrong.

Spelling and grammar fixed.

Renamed functions. I'll admit to being too damn lazy to think of a good name.

Great to hear that you'll do the merge and deploy! If you'd prefer to have squashed commits, I don't mind and can even squash them.

nickcmaynard commented 9 years ago

Merged, thank you John. I've also made a couple of tweaks, see later commits.

nickcmaynard commented 9 years ago

.. also deployed.