1

I'm parsing JSON data in Flask from POST request. Everything seems to be fine and works ok:

from flask import Flask
from flask import request
import io
import json
import pandas as pd

app = Flask(__name__)

@app.route('/postjson', methods = ['POST'])

def postJsonHandler():

    print (request.is_json)
    content = request.get_json()
    df = pd.io.json.json_normalize(content)
    print (df)
    return 'JSON posted'

app.run(host='0.0.0.0', port= 8090)

The output looks like this:

True 

          columns                                               data
0  [Days, Orders]  [[10/1/16, 284], [10/2/16, 633], [10/3/16, 532...

Then I try to transform json to pandas dataframe using json_normalize() function. So I receiving the result close to pandas dataframe but it is not yet it. What changes in the code should I do to receive classical Pandas Dataframe format with columns and data inside.

Thanks in advance.

1 Answer 1

1

Solved the problem. The idea was to use parameters of the json_normalize() function something like that:

df = pd.io.json.json_normalize(content, 'data')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.