jsonschema-protobuf
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/jsonschema-protobuf package

1.0.2 • Public • Published

jsonschema-protobuf

NPM

Converts JSON Schema to Protocol Buffers.

Install

npm install -g jsonschema-protobuf

Example

$ jsonschema-protobuf test.jsonschema
syntax = "proto2";

message person {
  message location {
    optional string city = 1;
    optional string state = 2;
  }

  required string name = 1;
  required int32 age = 2;
  required int32 income = 3;
  optional string universe = 4;
  optional boolean living = 5;
  repeated string alterEgos = 6;
}

test.jsonschema

{
  "type": "object",
  "name": "person",
  "properties": {
    "name": {"type": "string"},
    "age": {"type": "integer", "min": 0, "max": 120},
    "income": {"type": "number", "min": 0},
    "universe": {"type": "string", "enum": ["Marvel", "DC"]},
    "living": {"type": "boolean", "default": true},
    "alterEgos": {"type": "array", "items": {"type": "string"}},
    "location": {
      "type": "object",
      "properties": {
        "city": {"type": "string"},
        "state": {"type": "string", "regex": "/[A-Z]{2}/"}
      }
    }
  },
  "required": ["name", "age", "income"]
}

JS usage

var convert = require('jsonschema-protobuf')
var jsonschema = fs.readFileSync("test.jsonschema").toString()
var protobuf = convert(jsonschema)
console.log(protobuf)

TODO

  • Enum

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    41
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    41
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i jsonschema-protobuf

Weekly Downloads

41

Version

1.0.2

License

BSD

Last publish

Collaborators

  • karissa