I found a quick and easy solution to what I wanted using json_normalize() included in pandas 1.01.

from urllib2 import Request, urlopen
import json

import pandas as pd    

path1 = '42.974049,-81.205203|42.974298,-81.195755'
request=Request('http://maps.googleapis.com/maps/api/elevation/json?locations='+path1+'&sensor=false')
response = urlopen(request)
elevations = response.read()
data = json.loads(elevations)
df = pd.json_normalize(data['results'])

This gives a nice flattened dataframe with the json data that I got from the Google Maps API.

Answer from pbreach on Stack Overflow
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.DataFrame.to_json.html
pandas.DataFrame.to_json โ€” pandas 3.0.1 documentation
For other URLs (e.g. starting with โ€œs3://โ€, and โ€œgcs://โ€) the key-value pairs are forwarded to fsspec.open. Please see fsspec and urllib for more details, and for more examples on storage options refer here. ... Specify the IO mode for output when supplying a path_or_buf. Accepted args are โ€˜wโ€™ (writing) and โ€˜aโ€™ (append) only. mode=โ€™aโ€™ is only supported when lines is True and orient is โ€˜recordsโ€™. ... If path_or_buf is None, returns the resulting json format as a string.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ pandas โ€บ pandas โ€“ convert dataframe to json string
Pandas - Convert DataFrame to JSON String - Spark By {Examples}
November 5, 2024 - How do I convert a DataFrame to JSON in Python using pandas? You can use the to_json() method in Pandas to convert the DataFrame to JSON.
๐ŸŒ
Oreate AI
oreateai.com โ€บ blog โ€บ unlocking-data-seamlessly-converting-json-to-pandas-dataframes โ€บ acda9e349ae4d41b4988f3d7f1e365e1
Unlocking Data: Seamlessly Converting JSON to Pandas DataFrames - Oreate AI Blog
February 17, 2026 - What if your JSON data isn't in a file, but rather a string you've received from an API or generated elsewhere? No problem. You can still leverage Pandas. The process involves a couple of steps: First, you'll need to parse the JSON string into a Python object.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ pandas โ€บ pandas_json.asp
Pandas Read JSON
JSON is plain text, but has the format of an object, and is well known in the world of programming, including Pandas. In our examples we will be using a JSON file called 'data.json'. Open data.json. ... Tip: use to_string() to print the entire ...
Find elsewhere
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.read_json.html
pandas.read_json โ€” pandas 3.0.1 documentation
The encoding to use to decode py3 bytes. encoding_errorsstr, optional, default โ€œstrictโ€ ยท How encoding errors are treated. List of possible values . ... Read the file as a json object per line.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ pandas to json df.to_json() formatting
r/learnpython on Reddit: Pandas to JSON df.to_json() formatting
January 27, 2021 -

Suppose that I have the following dataframe:

    info     drinks reviews score menu   funfacts   
    input    1.0    1       2     4      1. funfacts, 2. fun fact, 3. fun fact

How could I transform this to the required JSON format? I tried Pandas(df.to_json) however the default formatting seems incorrect.

Snippet: `df3.to_json('File Name.json', orient='records')`

Expected output:

     {
       "info":[
          {
             "drinks":[
                "1.0"
             ],
             "reviews":[
                "1"
             ],
             "score":[
                "2"
             ],
             "menu":[
                "4"
             ],
             "funfacts":[
                "1. funfacts",
                "2. fun fact",
                "3. fun fact"
             ]
          }
       ]
    }

Current output:

    [
      {
        "drinks": "1.0",
        "reviews": "1",
        "score": "2",
        "menu": "4",
        "funfacts": "1. funfacts ,2. fun facts ,3 fun facts"
      }
    ]

Are there any arguments in pandas that I could use to get the desired format or do I need to use a different solution? Thanks

๐ŸŒ
w3resource
w3resource.com โ€บ pandas โ€บ dataframe โ€บ dataframe-to_json.php
Pandas DataFrame: to_json() function - w3resource
August 19, 2022 - DataFrame.to_json(self, path_or_buf=None, orient=None, date_format=None, double_precision=10, force_ascii=True, date_unit='ms', default_handler=None, lines=False, compression='infer', index=True) ... Returns: None or str If path_or_buf is None, returns the resulting json format as a string. Otherwise returns None. ... Download the Pandas DataFrame Notebooks from here.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ pandas โ€บ pandas-convert-json-to-dataframe
Convert JSON to Pandas DataFrame - GeeksforGeeks
July 23, 2025 - When working with data, it's common to encounter JSON (JavaScript Object Notation) files, which are widely used for storing and exchanging data. Pandas, a powerful data manipulation library in Python, provides a convenient way to convert JSON data into a Pandas data frame.
๐ŸŒ
GitHub
gist.github.com โ€บ Elsaveram โ€บ 3258db49eaac5e258401338ae17139a3
Convert json to pandas dataframe ยท GitHub
Convert json to pandas dataframe. GitHub Gist: instantly share code, notes, and snippets.
๐ŸŒ
Pandas
pandas.pydata.org โ€บ pandas-docs โ€บ version โ€บ 1.3.2 โ€บ reference โ€บ api โ€บ pandas.io.json.to_json.html
pandas.io.json.to_json โ€” pandas 1.3.2 documentation
pandas.io.json.to_json(path_or_buf, obj, orient=None, date_format='epoch', double_precision=10, force_ascii=True, date_unit='ms', default_handler=None, lines=False, compression='infer', index=True, indent=0, storage_options=None)[source]ยถ
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-read-json-files-with-pandas
How to Read JSON Files with Pandas? - GeeksforGeeks
July 23, 2025 - JSON (JavaScript Object Notation) store data using key-value pairs. Reading JSON files using Pandas is simple and helpful when you're working with data in .json format. There are mainly three methods to read Json file using Pandas Some of them are:
๐ŸŒ
NVIDIA Developer
developer.nvidia.com โ€บ blog โ€บ json-lines-reading-with-pandas-100x-faster-using-nvidia-cudf
JSON Lines Reading with pandas 100x Faster Using NVIDIA cuDF | NVIDIA Technical Blog
April 23, 2025 - To use information from JSON Lines in data processing pipelines, the tokens must often be converted into a Dataframe or columnar format, such as Apache Arrow. JSON readers, such as pandas.read_json convert input character data into a Dataframe organized by columns and rows.
๐ŸŒ
Statology
statology.org โ€บ home โ€บ how to convert a pandas dataframe to json
How to Convert a Pandas DataFrame to JSON
July 30, 2020 - import pandas as pd #create DataFrame df = pd.DataFrame({'points': [25, 12, 15, 19], 'assists': [5, 7, 7, 12]}) #view DataFrame df points assists 0 25 5 1 12 7 2 15 7 3 19 12 ยท df.to_json(orient='split') { "columns": [ "points", "assists" ], "index": [ 0, 1, 2, 3 ], "data": [ [ 25, 5 ], [ 12, 7 ], [ 15, 7 ], [ 19, 12 ] ] }
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ pandas read_json โ€” convert a json string to pandas object.
Pandas read_json โ€” Convert a JSON string to pandas object. - AskPython
January 18, 2023 - It focuses on operations on relational data, here we would convert JSON string pandas DataFrame with the help of the read_json() function. Multiple manipulations of the function will be carried out to receive the desired output.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ exporting-pandas-dataframe-to-json-file
Exporting Pandas DataFrame to JSON File - GeeksforGeeks
February 18, 2026 - To export a Pandas DataFrame to a JSON file we use the to_json() function. This function converts the DataFrame into a JSON format making it easy to store and share data.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-convert-api-json-data-into-pandas-dataframe
How to convert API JSON data into pandas dataframe
The fetched data in form of a GET request is first converted into JSON using json() method of request library. Later it is converted into dataframe using json_normalize() method of pandas.
๐ŸŒ
GitHub
github.com โ€บ pandas-dev โ€บ pandas
GitHub - pandas-dev/pandas: Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more ยท GitHub
Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more - pandas-dev/pandas
Starred by 48.2K users
Forked by 19.8K users
Languages ย  Python 91.0% | Cython 6.2% | C 1.5% | HTML 1.2% | Meson 0.1% | CSS 0.0%