AMS - is the intention to always return a hash?

34 views
Skip to first unread message

L. Preston Sego III

unread,
Oct 12, 2014, 3:56:24 PM10/12/14
to rails-a...@googlegroups.com
for example, if we are serializing an array, does that mean a key is required for the array?

Steve Klabnik

unread,
Oct 13, 2014, 1:58:44 AM10/13/14
to L. Preston Sego III, rails-a...@googlegroups.com
Generally speaking, it's considered best practice to always root your
JSON via an object. This is laregely due to a security flaw in
browsers that has since been patched up, but it's still basically a
given.

L. Preston Sego III

unread,
Oct 13, 2014, 10:57:18 AM10/13/14
to rails-a...@googlegroups.com, lt....@gmail.com
should we default to always having a root?

for single objects:
{ root: { object } }

array:
{ roots: [{ rootless object}, { rootless object }] }

?

then should arrays have the option to be super verbose with roots?

{ roots: [ {root: { object } , { root: { object } } ] }

Steve Klabnik

unread,
Oct 13, 2014, 10:59:18 AM10/13/14
to L. Preston Sego III, rails-a...@googlegroups.com
As of 0.10, that depends entirely on the particular adapter. JSON-API,
for example, has a root. HAL does not. Classic AMS usually does,
unless you ask for no root, or maybe the other way around, I forget.
Reply all
Reply to author
Forward
0 new messages