2

I am implementing a python API using flask framework, here is my code:

    current_months = [this_month_list]
    result = pd.concat(current_months)
    my_array = np.array(result['city'])
    freqs = Counter(my_array)
    return jsonify(freqs)

My problem is in creating the JSON object. By the above code the JSON is like:

{
'Riyadh': 50
'Jeddah': 10
'Los Angeles': 30}

However, I want to include a message to the JSON object. This is the result that I want to achieve:

{
'Message' : "I want to include this message"
'Result' : {
    'Riyadh': 50
    'Jeddah': 10
    'Los Angeles': 30
}

}

2 Answers 2

3

Just append them to a dictionary:

freqs = {
    'Message': 'Some msg',
    'Result': Counter(my_array)
}
return jsonify(freqs)
Sign up to request clarification or add additional context in comments.

Comments

1

So just wrap your data:

data = {
    'Message' : "I want to include this message"
    'Result' : freqs }
return jsonify(data)

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.