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 typingpy_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file py_json_to_proto-0.1.3.tar.gz
.
File metadata
- Download URL: py_json_to_proto-0.1.3.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.9.2 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e43eebc71286f985f025d7fe4b66fc44761b6fc5e18afc41fe6da5b49d0a3e84 |
|
MD5 | 7c4a9ff996eb75026c621d9d30891215 |
|
BLAKE2b-256 | 2bf4556f021a36b7fa6abed104825b458f3798ebb0837a71927a671168dc31fc |
File details
Details for the file py_json_to_proto-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: py_json_to_proto-0.1.3-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.9.2 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30e20a8110c90ae6ac47cc3e9cfebe7dca637b7a2afe8e21b317707c0afbf0a9 |
|
MD5 | 59bfc7cbfc3acdfa54401b1f5ffcd96d |
|
BLAKE2b-256 | 8cbd29f2506094a08a379d792792e97f799c7c1d387d3aa969efee3201311735 |