0

I am working on Flask app where I need to return list as response, how I can output as key with multiple values.

Like here

    a = [1,2,3]    
    return jsonify({ 'List': a })
    
    
    Output 
    {
         "Lsit":[1,2,3]
    }

How do i get

    {
        "List": ["1", "2", "3"],
    }

2 Answers 2

2

Can't you just use map()?

jsonify{'List': list(map(str,a))}
Sign up to request clarification or add additional context in comments.

Comments

2

use map to change every number to string.

a = [1, 2, 3]
return jsonify({ 'List': list(map(str, a)) })

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.