Using JSON Schema

! ! !

Using JSON Schema

! ! !

Learn and Apply JSON Schema by Example, with Javascript (Node.js) and Python Programs

!

Featuring JSON Schema draft 4

! ! !

Joe McIntyre!

!

! ! ! ! ! !

For Liz

"ii

Copyright

Copyright ? 2014 by Joe McIntyre. All rights reserved.!

!

First edition: July, 2014!

!

All trademarks used in this book belong to their respective owners.!

Source Code Licenses

The book contains Javascript, and Python source code. There are external libraries that are used by some of the programs. The following are the licenses that apply to each of these.!

Tiny Validator (for v4 JSON Schema)

Tiny Validator (for v4 JSON Schema), packaged in the file tv4.js, is made available under a public domain license. The source is available at,!

! The license is available at,!

!

jsonschema 2.3.0

A JSON Schema library for Python, made available under a MIT license. The source is available at,! !

The license is available at,! !

jsonlint

A JSON parser made available under a MIT license. The source is available at,! !

The license is available at,! !

Book Content

All Javascript and Python source code in the book text, and in the set of files accompanying the book, is made available under the following MIT license.!

The MIT License (MIT) Copyright (c) 2014 Joe McIntyre Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction,

"iii

including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.! This license is also provided as a file in the accompanying materials, available in each of the project repositories on GitHub. See the top level project for a list of the repositories,!

"iv

Preface

Some software technologies find themselves being used in a variety of contexts, useful without being cumbersome. They get widely used, don't get a reputation as being 'force-fit', and endure. JSON is emerging as one of those technologies.! In the message exchange space, JSON is commonly used in implementing RESTful web services. Its broad use reflects the flexibility of JSON formatted content to support iterative definition for message exchanges between systems, coexistence with a range of technologies, and ease of understanding.! A broad cross section of software programs include configuration files. Often these configuration files are supplemented by command line argument support, environment variables, and/or integration with external configuration systems. Over time, the complexity of software configuration has grown with the increasing use of networked resources and greater levels of customization for users. This has led to the evolution of configuration definitions to more flexible technologies such as JSON and XML.! Often the choice of configuration technology is related to the programming language, runtime, or operating system chosen for the program. However, many programs have cross platform requirements (now including supporting cloud deployments), and may have multiple runtimes operating different portions of the overall system. Thus, it is very desirable for the configuration technology to have support across languages and environments. The inclusion of Javascript (Node.js and web browser uses) and Python examples, for multiple operating systems, shows integration of JSON and JSON Schema with different runtimes.! In addition to configuration files, many programs also have data management requirements. While some programs have requirements suitable for using databases, others have more modest needs and are better suited to the flexibility of using JSON files. However, for JSON suited programs, as the content expands (both in the structure of the data model as well as the amount of data stored), there is greater risk of data consistency errors. Also, as is the case with many configuration files, updates to the data may be made with text editing tools and are subject to errors ? often minor. Finding these errors is often more work than correcting them ? a missing comma, misplaced closing } or ], or a typo in a keyword. Fortunately, there are two tools that address this well,!

? JSON syntax checkers, which find syntax errors.! ? JSON Schema, and its affiliated validation tools, which find content errors.! As JSON has gained support across a broad array of programming languages / runtime platforms, the use of JSON formatted files for configuration files and similar uses is now an available option for many projects.! JSON and JSON Schema are strong foundational technologies, with many avenues for building interesting and useful capabilities around them. Hopefully the examples spur some new design ideas in your projects.!

"v

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download