Automatically JSON.stringify b.send
See original GitHub issueThis is just a suggestion. There’s probably some reason this doesn’t make sense but: whenever I’m using b.send
to send a non-string message I want to stringify it so I end up doing e.g.
b.send(JSON.stringify([message_type,[cool_data,cooler_data]]));
And then obviously I end up using JSON.parse
at the receiving end.
Is there some reason b.send
and b.on('message',...
couldn’t/shouldn’t do this under the hood?
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Issue with JSON.stringify adding a extra \ and "" to my Json ...
It looks like you are placing a string as the value in your map. You should do something like: var objMap = {"JObject"...
Read more >Automatic JSON stringifycation replacer parameter · Issue #2822
I'd like to have every key of my objects in the data i send to my backend, but JSON.stringify removes the properties with...
Read more >JSON methods, toJSON - The Modern JavaScript Tutorial
The method JSON.stringify(student) takes the object and converts it into a string. The resulting json string is called a JSON-encoded or ...
Read more >JSON.stringify() - JavaScript - MDN Web Docs
JSON.stringify() converts a value to JSON notation representing it: Boolean , Number , String , and BigInt (obtainable via Object() ) objects ...
Read more >Converting Javascript Objects into Strings with JSON.stringify()
JSON stringification is the process of converting a Javascript object to a flat JSON string that can be used inside a program.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just started using this, so take my opinion with a grain of salt - but I would personally opt for configuration or some sort of middleware over growing the API for convenience functions like that. By extension, if half of people like JSON and the other half like msgpack, does the API grow to have send, sendjson, and sendmsgpack? Seems cleaner to let the user specify their preferred serialize/deserialize functions when they instantiate the Bugout instance. This would keep the API small, while still allowing people to use whatever serialization they prefer. Personally, I suspect most people will want to use JSON, so even making JSON.stringify/JSON.parse the default functions would probably be fine.
Personally I never like silent anything…it would be nice to have an event emitted when something goes wrong (and I can choose whether to set up a handler for that event or not). Even if all errors were sent to the same handler (for decrypt and decode), that would be nice. For simple cases like JSON, where we can expect users to use stringify/encode, it probably isn’t a big deal. However, it could be useful when somebody does something more esoteric (say, with msgpack, if they have custom types that aren’t available at both ends for whatever reason), having the error would make debugging easier.