Skip to content

to_json() for multi indexed dataframe is missing escapes #27045

Closed
@dickreuter

Description

@dickreuter

For df.to_json() the speech marks should be escaped. Currently, the json is not valid. This was already reported as an issue here #15288, but most likely incorrectly marked as duplicate with something else.

idx = pd.MultiIndex.from_product([['Zara', 'LV', 'Roots'],
                                  ['Orders', 'GMV', 'AOV']],
                                 names=['Brand', 'Metric'])
col = ['Yesterday', 'Yesterday-1', 'Yesterday-7', 'Thirty day average']

df = pd.DataFrame('-', idx, col)
df.to_json()

'{"Yesterday":{"["Zara","Orders"]":"-","["Zara","GMV"]":"-","["Zara","AOV"]":"-","["LV","Orders"]":"-","["LV","GMV"]":"-","["LV","AOV"]":"-","["Roots","Orders"]":"-","["Roots","GMV"]":"-","["Roots","AOV"]":"-"},"Yesterday-1":{"["Zara","Orders"]":"-","["Zara","GMV"]":"-","["Zara","AOV"]":"-","["LV","Orders"]":"-","["LV","GMV"]":"-","["LV","AOV"]":"-","["Roots","Orders"]":"-","["Roots","GMV"]":"-","["Roots","AOV"]":"-"},"Yesterday-7":{"["Zara","Orders"]":"-","["Zara","GMV"]":"-","["Zara","AOV"]":"-","["LV","Orders"]":"-","["LV","GMV"]":"-","["LV","AOV"]":"-","["Roots","Orders"]":"-","["Roots","GMV"]":"-","["Roots","AOV"]":"-"},"Thirty day average":{"["Zara","Orders"]":"-","["Zara","GMV"]":"-","["Zara","AOV"]":"-","["LV","Orders"]":"-","["LV","GMV"]":"-","["LV","AOV"]":"-","["Roots","Orders"]":"-","["Roots","GMV"]":"-","["Roots","AOV"]":"-"}}'

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions