Skip to content

pandas.read_sql_table switches double quotation wrapping keys and values to single quotation in JSON columns #30087

Open
@Magicbeanbuyer

Description

@Magicbeanbuyer

Code Sample

>>> df = pandas.read_sql_table('table_name', 'postgres:///db_name')
>>> df.head(1)

Problem description

I used pandas.read_sql_table() to fetch a table, in which there is a JSON column. In the returned dataframe, the double quotations wrapping the keys and values are all changed to single quotations.

Example of returned dataframe:

id name
1 {'first': 'Anna', 'last': 'Smith'}

However, JSON standards requires double quotation, on top of that, other Python package like json doesn't recognize JSON with single quotations.

Expected Output

id name
1 {"first": "Anna", "last": "Smith"}

Output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit           : None
python           : 3.7.3.final.0
python-bits      : 64
OS               : Windows
OS-release       : 10
machine          : AMD64
processor        : Intel64 Family 6 Model 142 Stepping 10, GenuineIntel
byteorder        : little
LC_ALL           : None
LANG             : None
LOCALE           : None.None

pandas           : 0.25.3
numpy            : 1.17.4
pytz             : 2019.3
dateutil         : 2.8.1
pip              : 19.3.1
setuptools       : 42.0.2.post20191203
Cython           : 0.29.14
pytest           : 5.3.1
hypothesis       : None
sphinx           : 2.2.2
blosc            : None
feather          : None
xlsxwriter       : 1.2.6
lxml.etree       : 4.4.2
html5lib         : 1.0.1
pymysql          : None
psycopg2         : 2.7.6.1 (dt dec pq3 ext lo64)
jinja2           : 2.10.3
IPython          : 7.9.0
pandas_datareader: None
bs4              : 4.7.1
bottleneck       : 1.3.1
fastparquet      : None
gcsfs            : None
lxml.etree       : 4.4.2
matplotlib       : 3.1.1
numexpr          : 2.7.0
odfpy            : None
openpyxl         : 3.0.2
pandas_gbq       : None
pyarrow          : None
pytables         : None
s3fs             : 0.4.0
scipy            : 1.3.1
sqlalchemy       : 1.3.11
tables           : 3.6.1
xarray           : None
xlrd             : 1.2.0
xlwt             : 1.3.0
xlsxwriter       : 1.2.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO SQLto_sql, read_sql, read_sql_query

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions