Multiline JSON doesn't multiline #328
-
I'm not sure if this is a bug or a feature request. I want to use JSON5 as an alternative to YAML in an extension for VSCode. In YAML really long strings are automatically multilined when stringified. This doesn't seem to be the case for JSON5. It doesn't stop here though. It seems that no matter how much I try (several hours later) I'm unable to automatically wrap 100+ character lines in strings. I've tried every possible combination of regex replace and reviver and replacer functions in parse and stringify, and it doesn't happen. I think I will have to resort to using a regex replace that sees if it's within quotes or single quotes and then does the word wrap replace, but this is difficult and annoying. Can you add an example on how to do this in the README as this is something that probably a good chunk of users of this package would need to do. It would also be nice to have clear documentation of how the stringify replacer and the parse reviver works. Are newlines transformed before or after these methods are run? Nice format and package otherwise. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Thanks for your interest in JSON5. However, the reason you're having problems with multiline strings is because JSON5 doesn't support multiline strings. It does support multiline comments, though. As far as the documentation for |
Beta Was this translation helpful? Give feedback.
-
The reason that I moved this to a discussion is because the original issue doesn't work as a feature request either. JSON5 is built on the syntax of ECMAScript 5, which doesn't support multiline strings. So JSON5 will not have added support for multiline strings either. |
Beta Was this translation helpful? Give feedback.
Thanks for your interest in JSON5. However, the reason you're having problems with multiline strings is because JSON5 doesn't support multiline strings. It does support multiline comments, though.
As far as the documentation for
reviver
andreplacer
, the API is identical toJSON
's and works in the same way.reviver
is called after each value is parsed whilereplacer
is called before each value is stringified.