Last active
August 29, 2015 14:03
-
-
Save colelawrence/590940dcb906cbb27eb3 to your computer and use it in GitHub Desktop.
Convert json to form formatted JSON
This file contains hidden or 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
process = (str, obj) -> | |
res = {} | |
bl = (cont_str, cobj) -> | |
if typeof cobj is 'object' | |
for k, v of cobj | |
bl cont_str + "[#{ k }]", v | |
else | |
res[cont_str] = cobj | |
bl str, obj | |
return res | |
o = { | |
h: | |
j: true | |
g: 2 | |
m: | |
w: true | |
m: false | |
s: true | |
} | |
Say JSON.stringify(process("child",o),null,2) | |
# { | |
# "child[h][j]": true, | |
# "child[h][g]": 2, | |
# "child[h][m][w]": true, | |
# "child[h][m][m]": false, | |
# "child[s]": true | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment