Created
May 3, 2012 13:48
-
-
Save hara-y-u/2585761 to your computer and use it in GitHub Desktop.
Walk JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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