hjson / hjson-cpp

Hjson for C++
https://hjson.github.io/
MIT License
70 stars 20 forks source link

toJson() #4

Closed damianorenfer closed 6 years ago

damianorenfer commented 7 years ago

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.

laktak commented 7 years ago

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.

trobro commented 7 years ago

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

damianorenfer commented 7 years ago

Ok, sounds good!

trobro commented 7 years ago

@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".

trobro commented 7 years ago

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

laktak commented 7 years ago

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.