Skip to main content

file:README.md

Project description

PyJsonToProto

Thanks for checking out PyJsonToProto, this is a port of https://github.com/json-to-proto/json-to-proto.github.io in to Python to be used in a number of applications using Protobufs

Installation

This package is published as a pip installable package.

pip install py_json_to_proto

How to use

CLI usage

The CLI is the name of the project abbreviated as jsp. Why? Try typing py_json_to_proto a ton of times

HELP:

usage: jsp.exe [-h] [--google_timestamp GOOGLE_TIMESTAMP] [--inline INLINE] [--input_file INPUT_FILE] [--output_file OUTPUT_FILE]

optional arguments:
  -h, --help            show this help message and exit
  --google_timestamp GOOGLE_TIMESTAMP
                        Add timestamp to imports if in json
  --inline INLINE       unsure...this could use a contribution
  --input_file INPUT_FILE, -i INPUT_FILE
                        The input file to convert
  --output_file OUTPUT_FILE, -o OUTPUT_FILE
                        The location to save the protos
jsp --input_file="test.json" --output_file="yolo.proto"

The input file used test.json

{
    "id": 23357588,
    "node_id": "MDEwOlJlcG9zaXRvcnkyMzM1NzU4OA==",
    "name": "protobuf",
    "full_name": "protocolbuffers/protobuf",
    "private": false,
    "arg2": 1009,
    "arg1": 11124
  }

The output of the file yolo.proto

syntax = "proto3";

message SomeMessage {
    uint32 id = 1;
    string node_id = 2;
    string name = 3;
    string full_name = 4;
    uint32 private = 5;
    uint32 arg2 = 6;
    uint32 arg1 = 7;
}

Code Usage

I would take a look at the cli code in cli.py to get a better feel.

from py_json_to_proto.convert import convert, Options

# Read in your json file and then convert to proto string
with open('test.json'), 'r') as file:
    data = convert(file.read(), Options(False, False))

# You're done, save the proto string
with open(args.output_file, 'w') as file:
    file.write(str(data))

Authors:

  • Benjamin Garrard

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_json_to_proto-0.1.3.tar.gz (6.4 kB view hashes)

Uploaded Source

Built Distribution

py_json_to_proto-0.1.3-py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page