hjson / hjson-js

Hjson for JavaScript
https://hjson.github.io/
MIT License
417 stars 49 forks source link

hjson.stringify() ignores 'toJSON()' methods #38

Open depeele opened 6 years ago

depeele commented 6 years ago

IT would be nice if hjson honored toJSON() in a way consistent with the standard JSON.stringify().

From [Mozilla Docs](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. JSON.stringify() calls toJSON with one parameter:

  • if this object is a property value, the property name
  • if it is in an array, the index in the array, as a string
  • an empty string if JSON.stringify() was directly called on this object

This could be accomplished by adding the following prior to hjson-stringify.js line 316:

if (typeof(value.toJSON) === 'function')  {
  value = value.toJSON();
}
laktak commented 6 years ago

Sorry, this project is EOL, see https://hjson.org

retorquere commented 5 years ago

That page links back here (via npm) and doesn't mention this project being EOL. What does the project being EOL mean in practice? Just that the spec is frozen and so this lib is frozen, but any bugs found will be fixed? Or is no activity going to happen on this lib at all?

dqsully commented 5 years ago

This project isn't EOL, but we are looking for contributors. See hjson/hjson#84