hjson-js icon indicating copy to clipboard operation
hjson-js copied to clipboard

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

Open depeele opened this issue 7 years ago • 3 comments

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

From Mozilla Docs

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();
}

depeele avatar Jul 12 '18 13:07 depeele

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

laktak avatar Sep 14 '18 18:09 laktak

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?

retorquere avatar Jan 09 '19 12:01 retorquere

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

dqsully avatar Feb 09 '19 02:02 dqsully