In Python, you can use the json module to convert a list to a JSON string. The json module is part of the Python standard library and provides functions for encoding and decoding JSON data.
Here is an example of how to use the json module to convert a list to a JSON string in Python:
Copy code
import json
my_list = ['apple', 'banana', 'orange']
# Convert the list to a JSON string
json_string = json.dumps(my_list)
print(json_string) # Output: ['apple', 'banana', 'orange']
You can also use the jsonify function from the flask module to convert a list to a JSON response in a Flask app.
The jsonify function takes a Python object and returns a Flask response object with the JSON representation of the object as the response body.
Here is an example of how to use the jsonify function to return a list as a JSON response in a Flask app:
Copy code
from flask import jsonify
@app.route('/fruit')
def fruit():
my_list = ['apple', 'banana', 'orange']
return jsonify(my_list)