From 457019b8f618ea1047c2ac2a559508299dffee74 Mon Sep 17 00:00:00 2001 From: John Owens Date: Thu, 15 Dec 2016 15:53:11 -0800 Subject: [PATCH] added 'separator' argument to json_normalize --- pandas/io/json.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pandas/io/json.py b/pandas/io/json.py index 0a6b8af179e12..fa123d5783958 100644 --- a/pandas/io/json.py +++ b/pandas/io/json.py @@ -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( @@ -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 @@ -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 @@ -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: