Skip to main content

json-protobuf provides a Json interface to Google's Protocol Buffers compiled in C++ code. The idea is that you can convert a protocol buffer object to a json representation which can be used in API:s.

Producing Code

json-protobuf provides a plugin for the protoc protocol buffer compiler (it ships with protocol buffers). This plugin tells protoc to produce a set of C++ output files, which define the JSON interface to protocol buffers using the json-spirit library (other libraries will/coul be supported).

First, obtain a copy of json-protobuf:

$ git clone git@github.com:mickem/json-protobuf.git
$ cd json-protobuf

Next, install json-protobuf:

$ python setup.py install

Finally, launch protoc and tell it to produce Lua output:

$ protoc -I/path/to/your/proto/files --json_out=/output/path file1.proto file2.proto

You simply need to add --json_out to the arguments to protoc to get it to produce the Json output files.

Under the hood, protoc is looking for the program protoc-gen-json somewhere in your $PATH. You can modify $PATH in lieux of installing the package, if you desire.

Missing plugin_pb2 Python Module

The protocol buffers Python installer does not install a file required by protoc-gen-lua at this time. The missing file is the Python interface to the compiler plugin plugin.proto. The protoc-gen-lua Python script may fail when importing the google.protobuf.compiler.plugin_pb2 module.

A thread on the protocol buffers mailing list discusses the issue.

At this time, the issue can be worked around by manually installing the missing file.

Assuming you have a working protoc compiler on your system and have the existing Python protocol buffers package installed, from the protocol buffers source code directory, run the following:

$ protoc -Isrc --python_out=/path/to/output/directory src/google/protobuf/compiler/plugin.proto

The command should produce no output if successful. Additionally, the file /path/to/output/directory/google/protobuf/compiler/plugin_pb2.py should have been created.

Next, find the location of the installed protocol buffer Python package. If you have locate, try finding it via locate descriptor_pb2.py. A common location is something like /usr/lib/python2.6/site-packages/protobuf-2.3.0-py2.6.egg/google/protobuf/. Navigate to this directory and:

$ mkdir compiler
$ touch compiler/__init__.py
$ cp /path/to/plugin_pb2.py compiler/plugin_pb2.py

In common English:

  1. Create a new directory, from the install root, google/protobuf/compiler
  2. Create an empty file, __init__.py in this directory. This tells Python that the directory contains Python modules.
  3. Copy the plugin_pb2.py file produced by protoc to this new directory.

Depending on the installed location of protocol buffers, these actions may require superuser or administrator privileges.

Compiling Produced Files

You should be able to compile the produced .h and .cc files like you would for protocol buffer output files. If you have an existing Makefile, project, etc, just add the produced .h and .cc files to it.

Download files

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

Source Distribution

json-protobuf-0.0.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

json_protobuf-0.0.1-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file json-protobuf-0.0.1.tar.gz.

File metadata

  • Download URL: json-protobuf-0.0.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for json-protobuf-0.0.1.tar.gz
Algorithm Hash digest
SHA256 fdbac55236877da8f4f8392fa5df735e9dfe51f1bee0603c683db67e9ed2284b
MD5 5e683a550ab30f35bf307e60eb8ee6b5
BLAKE2b-256 45dc1ad678a7e21b54b0aab706ef4a5d8a72257d6a1a5d13258bc21ce7923c7a

See more details on using hashes here.

File details

Details for the file json_protobuf-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: json_protobuf-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for json_protobuf-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0762ff8c0e4b2b64363be5cb82f2ccc3b2a00ceec0f92ac660c5af47584e5184
MD5 c5995ef857d40d5414bd09df467940af
BLAKE2b-256 5c332c97ef6fa6dc9612a1a0c23be396fae9777fa167b52ea6f64f93ea65034f

See more details on using hashes here.

Release history Release notifications | RSS feed

2.0.1

2 files

2.0.0

2 files

1.0.0

2 files

This release

0.0.1 This release

2 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