Skip to content

Commit

Permalink
separator parameter included (s). default value .
Browse files Browse the repository at this point in the history
  • Loading branch information
jvalhondo committed Oct 26, 2016
1 parent 84d8e2f commit 3430369
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.*~
*.pyc
*.log
*.pyc
*.DS_Store
*.directory
*.sql
*.xls
*.p12
*.cer
*.pem
*.egg-info

.project
.pydevproject

.idea
8 changes: 4 additions & 4 deletions flatten_json/flatten_json.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
def flatten_json(y):
def flatten_json(y, s='.'):
out = {}

def flatten(x, name=''):
if type(x) is dict:
for a in x:
flatten(x[a], name + a + '_')
flatten(x[a], name + a + s)
elif type(x) is list:
i = 0
for a in x:
flatten(a, name + str(i) + '_')
flatten(a, name + str(i) + s)
i += 1
else:
a = ''
Expand All @@ -17,7 +17,7 @@ def flatten(x, name=''):
except:
a = x.encode('ascii', 'ignore').decode('ascii')

out[str(name[:-1])] = a
out[str(name[:-len(s)])] = a

flatten(y)
return out

0 comments on commit 3430369

Please sign in to comment.