Skip to main content

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

Release files for py-json-to-proto 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-json-to-proto 0.1.3
File Size Uploaded
py_json_to_proto-0.1.3.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-json-to-proto 0.1.3
File Interpreter ABI Platform
py_json_to_proto-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 13.6 kB

Release files / py_json_to_proto-0.1.3.tar.gz

Download URL py_json_to_proto-0.1.3.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e43eebc71286f985f025d7fe4b66fc44761b6fc5e18afc41fe6da5b49d0a3e84
BLAKE2b-256 checksum
How to use checksums
2bf4556f021a36b7fa6abed104825b458f3798ebb0837a71927a671168dc31fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.9.2 Windows/10

Release files / py_json_to_proto-0.1.3-py3-none-any.whl

Download URL py_json_to_proto-0.1.3-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
30e20a8110c90ae6ac47cc3e9cfebe7dca637b7a2afe8e21b317707c0afbf0a9
BLAKE2b-256 checksum
How to use checksums
8cbd29f2506094a08a379d792792e97f799c7c1d387d3aa969efee3201311735
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.9.2 Windows/10

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page