pd.NA is converted to {} instead of null with pd.DataFrame.to_json · Issue #31615 · pandas-dev/pandas (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

@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.