Save chart as json and read back in python for RESTful API

I have an issue sending and reading plotly charts over my RESTful API.

The user can request to receive the plot in a json format. However, I want to direct the user on how to load in the response back into a plotly chart.

Any help would be greatly appreciated.

Here is a sample of what the API sends the user when the chart is requested:

import plotly.express as px

def send_user_fig():

df = px.data.gapminder().query("country=='Canada'")
fig = px.line(df, x="year", y="lifeExp", title='Life expectancy in Canada')

fig.to_json() # fig.to_dict() (does not work - not JSON serializable due to ndarray)

return fig

Here is a sample of how I want to direct the user on how to transform the response back into a plotly figure. this is where the error is:

# API returns fig in json format
api_response = send_user_fig()

fig = go.Figure(
    data=api_response.json()['data'],
    layout=api_response.json()['layout']
)
fig.show() # ERROR occurs