hjson / hjson-js

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

Bad String for Newline in String #29

Closed JhonnyJason closed 7 years ago

JhonnyJason commented 7 years ago

Hello, Having a giant hjson file containing language strings like:

"en": "hello I am a potentially very long String"

I use it as a Module inside a Javascript App - there it works perfectly in in the current way. Using the cli it give's me the error:

Error: Bad string containing newline at line 153,106

SO basicly there are tons of these cases where I have like:

"en": "hello I am such a long string that I will become continued
in the next line"

It would be awesome if this would't be a such a big deal :-)

laktak commented 7 years ago

That's not valid JSON and I'm not sure how you are parsing this a JSON.parse() won't accept your input:

SyntaxError: Unexpected token
 in JSON at position 67
    at JSON.parse (<anonymous>)

Are you using a custom parser? You only need to replace \n by \\n to make it parseable by Hjson.

JhonnyJason commented 7 years ago

Yhea I suppose it is not valid json. But I hoped that it is valid in hjson^^.

I'm using the Hjson.parse() from the hjson.min.js.

Probably it is an older version as I have it this way now since close to a year now.

So the issue here is either that an update in the meantime has made the parser less human friendly^^. Or that the CLI version behaves differently from the browser version.

But yhea I guess I could do a script to get rid of the /n's within the ""s.

laktak commented 7 years ago

The problem is that you were relying on a bug that has been fixed in the meantime. Hjson supports multiline strings - I'm not sure though if that is what you want.

The easiest way is to use the old version to pipe it through - so you'll get it reformatted and it should then be working with the new version.

laktak commented 7 years ago

I hope this helped solve your problem.

JhonnyJason commented 7 years ago

yes Problem solved - thank you! :-)