Skip to content

Instantly share code, notes, and snippets.

@chapmanjacobd
Created November 21, 2023 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chapmanjacobd/de0ef47710a2cb03b3dd14a3583d5397 to your computer and use it in GitHub Desktop.
Save chapmanjacobd/de0ef47710a2cb03b3dd14a3583d5397 to your computer and use it in GitHub Desktop.
simple normalized JSON
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