Skip to content

deepbaksu/json-to-protobuf-definition

Repository files navigation

Convert JSON to Protocol Buffer definition

npm version CI codecov dependencies Status devDependencies Status Maintainability

{
  "name": "Mo Kweon",
  "some_property": 1234
}

to

message Root {
  string name = 1;
  int64 some_property = 2;
}

Install

npm install -D json-to-protobuf-definition
yarn add -D json-to-protobuf-definition

How to use

import {
  convertProtoMessageToString,
  parseRootObjectToProtoMessage,
} from "json-to-protobuf-definition";

// obtained from JSON.parse('{"name": "Mark Hahn""}')
const input = {
  name: "Mark Hahn",
};

const message = parseRootObjectToProtoMessage(input);
console.log(convertProtoMessageToString(message));
// message Root {
//   string name = 1;
// }

How to develop

yarn # install dependencies
yarn test # run test
yarn lint # run lint or `yarn lint --fix` to fix the lint issues