hjson/hjson-cpp

toJson()

damianorenfer opened this issue · 6 comments

Hi,

It is great to have an hjson implementation in C++, thank you! I was wondering if there is any plan to implement a toJson() feature which would allow us to convert hjson content to json.

The Javascript implementation supports this by setting the quotes and separator options.

Currently EncoderOptions allows you to set quoteAlways but a PR would be needed to add a separator option. But this is @trobro's project.

Good idea, I'll have a look at adding a separator option.

Ok, sounds good!

@laktak I now start using the .json test result files for comparison and noticed that the test charset2 contains "\uffff", and the json result file contains unescaped bytes as representation for that code point (in contrast to the hjson result file which contains the escaped representation). However, the code point is defined as "not a character" and "can be used to guess a text's encoding scheme, since any text containing these is by definition not a correctly encoded Unicode text":

https://en.wikipedia.org/wiki/Specials_(Unicode_block)

The JSON definition allows "\uffff", but basically says that decoders can crash if they want to when encountering it...

https://tools.ietf.org/html/rfc7159#section-8.1

I'll just change the result .json files in this repository to use the escaped representation "\uffff".

@damianorenfer I've created PR #5 with a function MarshalJson, do you think this would be a good solution?

The json results are produced by the JavaScript json implementation. The charset2 test is new though so I'll look at it again when I add it to the other implementations.