question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: in dump/safeDump support toJSON API

See original GitHub issue

toJSON documented here for JSON.stringify:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#toJSON()_behavior

If an object being stringified has a property named toJSON whose value is a function, then the toJSON() method customizes JSON stringification behavior: instead of the object being serialized, the value returned by the toJSON() method when called will be serialized.

If dump and safeDump would support this, js-yaml would be better as a direct replacement for JSON. For example, Immutable provides toJSON. Could be optional, as far as I am concerned, so it’s backwards compatible.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
puzrincommented, Jan 19, 2018

IMHO it’s better to keep things separate. If you know you can normalize object to json, then you can do:

yaml.safeDump(JSON.parse(your_obj.toJSON()))

This should work right now and does not require any changes.

0reactions
puzrincommented, Jan 23, 2018

Could you then refer/move new info to existing issue and close this one?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature request: Limit fields returned from API calls
So if I asked for data about 100 tickets, I could potentially get 100,000 lines of JSON because it includes all the custom_fields...
Read more >
performance.toJSON() - Web APIs - MDN Web Docs
The toJSON() method of the Performance interface is a serializer; it returns a JSON representation of the Performance object.
Read more >
Feature Request: JSON Format Tag - Laserfiche Answers
Hello,. Lately I've had an increasing number of Workflows that use the Web Request to interact with APIs using data collected in a...
Read more >
Issue tracking system and product feature requests
To view issue trackers, see Search for or create issues and feature requests, by product. To report an issue with the Google Cloud...
Read more >
Using fromJSON() | ArcGIS Maps SDK for JavaScript 4.25
JSON in this format is typically created from a toJSON() method or a query via ... you can require the esri/renderers/support/jsonUtils object and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found