Skip to content

Instantly share code, notes, and snippets.

@akluth
Created May 2, 2013 20:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save akluth/5505005 to your computer and use it in GitHub Desktop.
Save akluth/5505005 to your computer and use it in GitHub Desktop.
CoffeeScript: JSON-Objects, Arrays
# Considering an JSON object like this one:
#
# {
# "store": {
# "foo": {
# "value":"bar"
# }
# },
# "anotherstore": {
# "wat":{
# "value":"dat"
# }
# }
# }
#
# To get the "root" elements (e.g. 'store', 'anotherstore') use this construct:
for name of obj
console.log name
# To get the objects (e.g. 'foo', 'wat') of those elements
for i of obj
console.log "%j", obj[i]
# It took a quite long time to get me there...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment