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"],
    }
davidism
  • 110,080
  • 24
  • 357
  • 317
alex3465
  • 324
  • 2
  • 14

2 Answers2

2

Can't you just use map()?

jsonify{'List': list(map(str,a))}
Thavas Antonio
  • 5,542
  • 1
  • 11
  • 33
2

use map to change every number to string.

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