Package: json-schema-codegen
JSON-Schema CodegenThis python library consumes JSON-Schema and generates C++ or Python code.  It generates structures to hold the values defined in the schema, restricting the values according to the schema.Python Requirements for Code GenerationThese requirements should be satisfied whenpip3installingjson-schema-codegen.python 3.7jinja2stringcaseInstallationpip3installjson-schema-codegenC++ Generated CodeSupported Schema Features in C++ code generationA C++ class is generated for each schema node according to the schema'stypeproperty.  Schemas without atypeproperty, with the exception of combining operators*Of, are not supported.type: stringminLengthmaxLengthpatternformat=date-time (enforces ISO8601 format)format=uuid (enables string object to be populated with a uuid)type: string with enumtype: integermaximumminimumexclusiveMaximumexclusiveMinimummultipleOftype: numbermaximumminimumexclusiveMaximumexclusiveMinimummultipleOftype: booleantype: nulltype: arrayitemsminItemsmaxItemstype: objectpropertiesrequiredallOfanyOfoneOfReferences$refreferences are supported for array items, object properties, allOf, anyOf, and oneOf.  However, the caller must provide a "resolver" class which translates the reference into a class name and namespace.Dependencies of the C++ generated codeboost (boost::optional and boost::variant among others)rapidjson 1.1C++11UsageSeeexample_usage.pyfor a more elaborate example on generating C++ code.importjsonschemacodegen.cppascppsimpleResolver=cpp.SimpleResolver()output_dir="/tmp"generator=cpp.GeneratorFromSchema(src_output_dir=output_dir,header_output_dir=output_dir,resolver=simpleResolver,namespace=[],src_usings=[])sampleSchema={"type":"string"}generator.Generate(sampleSchema,'Example','example')Python Generated CodeA Python3 class is generated for each schema node; the class encapsulating the data described by the schema.  The class accepts in its constructor python primative data types that match the format described the the schema.  Each class has aSerializablemethod which returns data in a format that can be serialized.JSON (de-)serialization does not happen in the actual class.  This allows for flexibility to use other line-formats, for example, YAML.Supported schema features for generating Python codetype: stringminLengthmaxLengthpatternenumtype: integermaximumminimumexclusiveMaximumexclusiveMinimummultipleOfenumtype: numbermaximumminimumexclusiveMaximumexclusiveMinimummultipleOfenumtype: booleantype: nulltype: arrayitemsminItemsmaxItemstype: objectpropertiesrequiredallOfanyOfoneOfComponent schemas with thetitleproperty.Example usage for generating Python codeFor a more elaborate example, seeexample_python.pyfromjsonschemacodegenimportpythonaspygenimportjsonwithopen('schema.json')asfp:generator=pygen.GeneratorFromSchema('output_dir')generator.Generate(json.load(fp),'Example','example')This example will create the fileoutput_dir/example.pycontaining the Python3 classExampleand nested classes as required.Using the generated code looks like this:importexampleimportjsonjsonText='["an example string in an array"]'obj=example.Example(json.loads(jsonText))print(json.dumps(obj,default=lambdax:x.Serializable()))LicenseGPLv2