Skip to content

pd.NA is converted to {} instead of null with pd.DataFrame.to_json #31615

Closed
@pvieito

Description

@pvieito

Code Sample

import numpy as np
import pandas as pd

pd.DataFrame([[np.nan]], columns=["NA"]).to_json(orient="records")
# '[{"NA":null}]'
pd.DataFrame([[None]], columns=["NA"]).to_json(orient="records")
# '[{"NA":null}]'
pd.DataFrame([[pd.NA]], columns=["NA"]).to_json(orient="records")
# '[{"NA":{}}]'

Problem Description

pd.NA should behave as np.nan and None when converting a DataFrame to JSON.

Expected Output

In the resulting JSON the pd.NA instances should be converted to JSON's null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    IO JSONread_json, to_json, json_normalizeNA - MaskedArraysRelated to pd.NA and nullable extension arrays

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions