Requests for comment/JSON validation

This request for comments discusses JSON validation.

Background
As we increasingly store content in JSON, usually via ContentHandler, there is a need for a standardized JSON validation system that meets the requirements of Wikimedia projects. We currently have two different solutions deployed to the Wikimedia cluster: the JsonSchema class bundled in the EventLogging extension, and the json-schema library that is a development dependency of MediaWiki core and included in the  repository.

Problem
We are using multiple validators in production, neither of which is suitable for our needs. Each has something the other does not: while the EventLogging schema validator supports localizable error messages, it does not support JSON schema v4 features (test suite). The json-schema library included in core has the opposite problem. This will grow as a problem as more extensions are developed to make use of ContentHandler functionality and there is an inconsistent practice as the tradeoff is made between sophisticated schema and multilingual support.

Proposal
Based on an agreed-upon set of requirements, we should adopt a schema validator and implement it in MediaWiki core.

Requirements
These are the current proposed requirements:
 * Support for localized error messages (i18n)
 * Compliance with JSON Schema Version 4, maybe version 3 as well if there are compatibility issues
 * Who needs this and why? Is v4 a draft spec? When will it be finalized and are people expected to support it before finalization?
 * For example, the extension.json schema uses features like "anyOf". Yes, it's a draft spec, and there are already implementations that support the draft spec. Legoktm (talk) 05:01, 3 October 2016 (UTC)
 * Direct support for validating PHP objects/arrays, so they don't need to be converted into JSON first
 * Why? Is PHP special?
 * The main purpose is that we only parse the JSON once, where it is converted into a PHP object/array. Then if it is valid JSON, it gets passed to the validator which checks the properties/values/etc. but we don't want to have to reparse the JSON again, so it should be able to use the PHP object/array that we already parsed. Legoktm (talk) 05:01, 3 October 2016 (UTC)