top | item 28668560

(no title)

roncohen | 4 years ago

Couple of gripes:

    - Still no date type
    - Why make it more loose? Like "Strings may be single quoted." doesn't bring any value.

discuss

order

Cthulhu_|4 years ago

What would a date type look like? An ISO-8601 string is probably as good as it'll get, else you end up with an object containing loads of additional information like timezones, offsets, etc. There's also https://json-schema.org/understanding-json-schema/reference/... for a formalized date format in JSON.

The looseness seems to be aimed at human authors who want to write JSON as if it were JS, so mainly package.json. But, json is not ideal for configuration for multiple reasons.

rbut|4 years ago

If you wanted JSON to parse into actual date objects, you could always do:

  {
    thisIsADate: new Date('1995-12-17T03:24:00Z')
  }
It would be simple enough for parsers in other languages to parse this into their own date objects. Much simpler than using regexs to find ISO strings.

pawelduda|4 years ago

Useful when you need to input already double-quoted value.

But it's a matter of taste still and nothing that we couldn't do before. Such changes will lead to meetings where programmers discuss JSON5 quoting choices (yes, it will be a thing).

AlfeG|4 years ago

It brings it closer to JavaScript behavior I guess. I guess it's nice to have ability to copy random js object declaration to actual json without editing

alpaca128|4 years ago

I agree about the single quotes, but many use single quotes for strings in JS and so it's understandable to have this consistent.

rbut|4 years ago

Because:

  ‘I am “really” angry’
Is much nicer than:

  “I am \”really\” angry”

peoplefromibiza|4 years ago

and now you have two problems

is this any better?

    'I\'m "really" angry, don\'t do it again!'
in many languages single quotes are used as apostrophes and are very very common, much more common than double quotes.

eptcyka|4 years ago

Json is not meant to be human readable or writeable.

The_Colonel|4 years ago

Single quote strings are useful when the string contains many double quotes (e.g. XML with attributes).