Skip to content

Instantly share code, notes, and snippets.

@hara-y-u
Created May 3, 2012 13:48
Show Gist options
  • Save hara-y-u/2585761 to your computer and use it in GitHub Desktop.
Save hara-y-u/2585761 to your computer and use it in GitHub Desktop.
Walk JSON
walk = (obj, fn, map = 'root') -> #fn(map, leaf)
if obj instanceof Array
for o in obj
walk o, fn, map + "[#{_i}]"
else if typeof obj is 'object'
for key of obj
walk obj[key], fn, map + ".#{key}"
else
fn map, obj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment