Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print/parse JSON #142

Closed
13 of 14 tasks
CoDEmanX opened this issue Jan 15, 2016 · 12 comments
Closed
13 of 14 tasks

Print/parse JSON #142

CoDEmanX opened this issue Jan 15, 2016 · 12 comments

Comments

@CoDEmanX
Copy link

CoDEmanX commented Jan 15, 2016

Spec: https://developers.google.com/protocol-buffers/docs/proto3#json

  • Basic types formatting
  • Map field
  • Well-known types
  • Well-known types: Any
  • Well-known types: Timestamp
  • Printer/parser options
  • Printer option: Emit fields with default values
  • Printer option: Emit fields with default values, but oneof fields should still be printed once
  • Printer option: Emit fields with default values, but without messages
  • Parser option: Ignore unknown fields
  • Printer option: Use proto field name instead of lowerCamelCase name
  • Printer option: Emit enum values as integers instead of strings
  • Interop test against Google implementation
  • Interop test against Google implementation: well-known types
@xitep
Copy link
Contributor

xitep commented Jan 15, 2016

isn't formatting data as json better handled with something like serde_json?

@stepancheg
Copy link
Owner

@CoDEmanX Actually, binary protobuf is quite portable. It is designed for that, and encoding is well specified.

Protobuf encoding as JSON is needed to be implemented one day. It is also well specified, but it is not a priority, because encoding as JSON is not a primary goal of protobuf.

@CoDEmanX
Copy link
Author

I'm not concerned about portability actually, I'm looking for a way to make protobuf human-readable. Debug printing is human-readable, except that it lacks line breaks (maybe just on Windows?), and binary data is oddly encoded, but I need it encoded as true binary data. Because I have no Rust knowledge, JSON would be the most straightforward solution, because it would be human-readable and even a browser could decode the binary bits.

I guess I could write protobuf messages to file and read them back in with e.g. Node.js and try to convert them to JSON there...

As for the future of rust-protobuf: it would be great if it could parse protobuf to native Rust data structures. From there to JSON would probably be a lot easier, maybe there's even a crate for this already...

@stepancheg
Copy link
Owner

@CoDEmanX Note, pretty-printed serialization has been implemented recently. See d3b5647.

@wilg
Copy link

wilg commented Jun 21, 2018

I'm very new to Rust so I can't necessarily help with this for a while, but having a canonical JSON format that can be both serialized and deserialized is a very useful feature because it lets you use the Protobuf toolchain and generated code with a robust JSON wire format or have human editable config files that are strongly typed and easily read via protobuf (which is one of my use cases).

@stepancheg
Copy link
Owner

@wilg JSON parser and formatter is work in progress, e. g. 4d4c620.

Help is appreciated by the way.

Also, protobuf supports own text format, which is not JSON, and it should work now already.

@stepancheg stepancheg changed the title Format as JSON? Print/parse JSON Aug 21, 2018
@stepancheg
Copy link
Owner

Done except for the special handling of Any type.

Any is not implemented well in rust-protobuf (i. e. type registry is not implemented), so handling of Any is postponed.

@Ubehebe
Copy link

Ubehebe commented Dec 3, 2018

@stepancheg Can you publish a version of this crate that exports the json module? IIUC, it's on master but not the latest release (2.2).

@stepancheg
Copy link
Owner

@Ubehebe it is not easy: master version of protobuf is not compatible with current stable version (lots of things changed in codegen, reflection and APIs).

Porting it to stable version is possible, but hard.

It is relatively easy to backport JSON printing only (stable version does not implement reflection for mutability reflection), but I'm not sure there's a demand for printing only.

@aaronshim
Copy link
Contributor

Hi, just a question: Is there a reason why this functionality (which was backported for v2.9 according to https://docs.rs/protobuf/2.9.0/protobuf/json/index.html) was removed from the v2.10 branch? Thank you!

@stepancheg
Copy link
Owner

@aaronshim it broke backwards compatibility with generated code, unfortunately.

I wanted to implement it backwards-compatible way, but that's a significant amount of work.

@stepancheg
Copy link
Owner

Version 2.9.0 is yanked BTW

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants