Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why not support for single quote string? #13

Closed
ysmood opened this issue Oct 27, 2016 · 5 comments
Closed

Why not support for single quote string? #13

ysmood opened this issue Oct 27, 2016 · 5 comments

Comments

@ysmood
Copy link

ysmood commented Oct 27, 2016

I expect hjson

a: 'test'

to represent

{
  "a": "test"
}

But I only get

{
  "a": "'test'"
}

If you don't want to break the spec, please add an option to enable it.

@laktak
Copy link
Member

laktak commented Oct 27, 2016

You can do this with DSF as long as you use a new line for each value:

var Hjson=require("hjson");

var sampleText=`
{
  test: 'single quoted string'
}
`;

var sq={
  name: "singleQuotes",
  parse: function (value) {
    if (/^'.*'$/.test(value))
      return value.substr(1, value.length-2);
  },
  stringify: function (value) {},
};

var res=Hjson.parse(sampleText, { dsf: [ sq ] });
console.log(res.test);

@ysmood
Copy link
Author

ysmood commented Oct 28, 2016

That's great. Thanks!

@leviwheatcroft
Copy link

@laktak in #65 you explained the reluctance to include single quotes, which is fine. But I think this should be mentioned somewhere, particularly in your javascript readme.. because it seems to me like a problem that people will inevitably run into. hjson is for humans to use, and javascript type humans are used to using quotes and apostrophe's interchangeably.

As an example... I've been staring at this error for a few hours

hint: 'found '}' in a string value, your mistake could be with:\n > 'fill' }\n (unquoted strings contain everything up to the next line!)' }

I thought the problem was that the string being parsed had been escaped somehow, but only now I realise that the problem is the use of single quotes.

@laktak
Copy link
Member

laktak commented Apr 26, 2017

@leviwheatcroft you should see a better error message online/with 2.4.2.

@laktak
Copy link
Member

laktak commented Jul 13, 2017

@ysmood @leviwheatcroft this is now supported in 3.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants