Skip to content

added 'separator' argument to json_normalize #14949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pandas/io/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def to_json(path_or_buf, obj, orient=None, date_format='epoch',
default_handler=None, lines=False):

if lines and orient != 'records':
raise ValueError(
"'lines' keyword only valid when 'orient' is records")
raise ValueError(
"'lines' keyword only valid when 'orient' is records")

if isinstance(obj, Series):
s = SeriesWriter(
Expand Down Expand Up @@ -726,8 +726,8 @@ def nested_to_record(ds, prefix="", level=0):
def json_normalize(data, record_path=None, meta=None,
meta_prefix=None,
record_prefix=None,
separator='.',
errors='raise'):

"""
"Normalize" semi-structured JSON data into a flat table

Expand All @@ -744,6 +744,9 @@ def json_normalize(data, record_path=None, meta=None,
If True, prefix records with dotted (?) path, e.g. foo.bar.field if
path to records is ['foo', 'bar']
meta_prefix : string, default None
separator : string, default '.'
Nested records will generate names separated by separator,
e.g., for separator='.', { 'foo' : { 'bar' : 0 } } -> foo.bar
errors : {'raise', 'ignore'}, default 'raise'
* ignore : will ignore KeyError if keys listed in meta are not
always present
Expand Down Expand Up @@ -828,7 +831,7 @@ def _pull_field(js, spec):
lengths = []

meta_vals = defaultdict(list)
meta_keys = ['.'.join(val) for val in meta]
meta_keys = [separator.join(val) for val in meta]

def _recursive_extract(data, path, seen_meta, level=0):
if len(path) > 1:
Expand Down