1

Taken from https://github.com/interagent/http-api-design#downcase-paths-and-attributes

Downcase attributes as well, but use underscore separators so that attribute names can be typed without quotes in JavaScript, e.g.:

service_class: "first"

What does it mean by "attribute names can be typed without quotes"?

Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
  • 2
    You've tagged this question with `json`, so I wanted to point out that, if you are using JSON, your names in the name-value pairs must always be quoted. That is a requirement for valid JSON ( http://stackoverflow.com/a/2068074/1281907 ). – talemyn Sep 29 '14 at 18:33

2 Answers2

1

If you have:

{ foo-bar: 1 }

You'll get a "SyntaxError: Unexpected token :" error since the "-" is mistaken as a subtraction operator:

{ foo - bar : 1 }

Then you need quotes to indicate that this is a property name:

{ "foo-bar": 1 }

If you use underscores instead of dashes, there is no ambiguity:

{ "foo_bar": 1 }
{ foo_bar: 1 } // This also works
Ates Goral
  • 137,716
  • 26
  • 137
  • 190
1

This is a valid Javascript literal:

{ foo_bar: 'baz' }

This isn't:

{ foo-bar: 'baz' }

The latter must be:

{ 'foo-bar': 'baz' }

That's all it's talking about; the preceding paragraph referred to "dash-separated path names" and followed by saying you shouldn't use dashes in JSON. It's not snake vs. camelCase, it's snake vs. "dash-case".

deceze
  • 510,633
  • 85
  • 743
  • 889