Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

feature request: toJSON() #19

Closed
ronkorving opened this issue Oct 3, 2011 · 3 comments
Closed

feature request: toJSON() #19

ronkorving opened this issue Oct 3, 2011 · 3 comments

Comments

@ronkorving
Copy link

It would be really nice if msgpack could directly turn its binary representation into a JSON string, avoiding parse from msgpack -> stringify to JSON. Besides the potential performance benefit, not having this step would avoid a lot of object creation, which could really help the garbage collector to take it easy.

@download13
Copy link

toJSON is normally a function used for returning JSON serializable objects from an object that doesn't allow enumeration, or for when you want JSON to only serialize a portion of the object.
For example:

function A() {
  this.t = 4;
  this.prop = "test";
}
A.prototype.toJSON = function() {
  return {prop: this.prop}
}

var a = new A;

If a is ever stringifyed with JSON, you will end up with {"prop": "test"} instead of {"t": 4, "prop": "test"}.

tl;dr You might want to change this request to use a different function name.

@godsflaw
Copy link
Collaborator

Can you help clarify? If I have an array:

var myArray = [ "one", "two" ];

and I pack that with msgpack.pack:

var binaryData = msgpack.pack(myArray);

You want a function that let's you say:

var jsonString = msgpack.unpack(binaryData, 'JSON');

I tend to agree with download13, we should not call it msgpack.toJSON(). I think making something like this an option to unpack is more desirable.

Is this what you mean?

mikepb added a commit to mikepb/node-msgpack that referenced this issue Aug 19, 2013
mikepb added a commit to mikepb/node-msgpack that referenced this issue Aug 19, 2013
@godsflaw
Copy link
Collaborator

closing because of #50

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

No branches or pull requests

3 participants