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

Serializing protobufs to json #351

Closed
mwildehahn opened this issue Nov 6, 2015 · 8 comments
Closed

Serializing protobufs to json #351

mwildehahn opened this issue Nov 6, 2015 · 8 comments
Labels

Comments

@mwildehahn
Copy link

with proto3, protocol buffers now have a standard json format, is there a way to leverage this with this library?

my use case is caching protocol buffers in local storage. currently i've been base64 encoding the messages before storing them. this becomes more complex with the Map type.

@dcodeIO
Copy link
Member

dcodeIO commented Nov 18, 2015

Have you tried Message#encodeJSON?

@lanttu
Copy link

lanttu commented Dec 16, 2015

The method doesn't seem to use canonical proto3 JSON encoding as specfied in here: https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json

@joeblew99
Copy link

Did you sort out if Google's support for json, makes bufferjs redundant ?

I suspect that bufferjs allows marshalling between json and PB client side, and grpc allows marshalling between the two server side at the facade.

I would like to know what the answer to this is from an architectural perspective.

@leeyeh
Copy link

leeyeh commented Feb 23, 2016

+1.

My use case is to encode to and decode from the canonical formatted JSON data, since React Native's js-native bright is text-based.

@dcodeIO
Copy link
Member

dcodeIO commented Nov 28, 2016

Closing this for now.

protobuf.js 6.0.0

Feel free to send a pull request if this is still a requirement.

@dcodeIO dcodeIO closed this as completed Nov 28, 2016
@aidansteele
Copy link

@dcodeIO Sorry, it's not clear to me - is the issue closed because any changes discussed here are no longer relevant (due to rewrite) or because protobuf.js 6.x now supports the functionality?

@dcodeIO
Copy link
Member

dcodeIO commented Apr 11, 2017

or because protobuf.js 6.x now supports the functionality

Not quite, but the default toJSON implementation of message instances should be close.

someMessage.toJSON();
// or
SomeMessage.toObject(someMessage, util.toJSONOptions);

Not yet supported:

  • "NaN", "Infinity" strings for floats
  • Any, Timestamp, Duration, Struct, Wrappers, FieldMask, ListValue, Value, NullValue are handled like messages

Feel free to reopen!

dcodeIO added a commit that referenced this issue Apr 11, 2017
…lity of NaN and Infinity + additional documentation of util.toJSONOptions, see #351
@dcodeIO
Copy link
Member

dcodeIO commented Apr 11, 2017

Related: #677

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

No branches or pull requests

6 participants