Created
November 21, 2023 05:20
-
-
Save chapmanjacobd/de0ef47710a2cb03b3dd14a3583d5397 to your computer and use it in GitHub Desktop.
simple normalized 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
def nosql_to_sqlv1(dict_or_arr): | |
import pandas as pd | |
dict_or_arr = objects.flatten_dict_single_parents(dict_or_arr) | |
dict_or_arr = objects.flatten_grandparents(dict_or_arr) | |
df = pd.json_normalize(dict_or_arr, sep="_") | |
df = pd_utils.columns_snake_case(df) | |
dict_or_arr = df.to_dict(orient="records") | |
if len(dict_or_arr) == 1: | |
return dict_or_arr[0] | |
else: | |
return dict_or_arr | |
. . . | |
if args.nested_list: | |
# try to find a nested list if possible | |
body = iterables.get_list_with_most_items(body) or body | |
if isinstance(body, list): | |
body = [nosql_to_sql(d) for d in body] | |
elif isinstance(body, dict): | |
# settle for a single dict | |
body = nosql_to_sql(body) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment