Skip to content

Commit

Permalink
use json loads to beter read reponses from API
Browse files Browse the repository at this point in the history
  • Loading branch information
jdebacker committed Mar 4, 2024
1 parent d8f910a commit 0a9172e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ogcore/demographics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import time
import numpy as np
import json
import scipy.optimize as opt
import pandas as pd
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -68,7 +69,9 @@ def get_un_data(
# Check if the request was successful before processing
if response.status_code == 200:
# Converts call into JSON
j = response.json()
un_str = response.text
j = json.loads(un_str)
# j = response.json()
# Convert JSON into a pandas DataFrame.
# pd.json_normalize flattens the JSON to accommodate nested lists
# within the JSON structure
Expand All @@ -80,7 +83,10 @@ def get_un_data(
# call the API for the next page
response = get_legacy_session().get(target)
# Convert response to JSON format
j = response.json()
un_str = response.text
print(un_str)
j = json.loads(un_str)
# j = response.json()
# Store the next page in a data frame
df_temp = pd.json_normalize(j["data"])
# Append next page to the data frame
Expand Down

0 comments on commit 0a9172e

Please sign in to comment.