Create CSV data from JSON data
Easily convert one data format to another. This applies not only to json or csv formats but many widely used data formats.
Prompt
You are an expert in data formatting. Convert the following JSON object into CSV format. ``` [ { "name": "Jane Smith", "age": 25, "occupation": "Data Scientist" }, { "name": "Bob Johnson", "age": 42, "occupation": "Software Developer" }, { "name": "Emily Davis", "age": 37, "occupation": "Product Manager" }, ] ```
Output
name,age,occupation Jane Smith,25,Data Scientist Bob Johnson,42,Software Developer Emily Davis,37,Product Manager
API Request
PYTHON
1 import cohere 2 3 co = cohere.ClientV2(api_key="<YOUR API KEY>") 4 5 response = co.chat( 6 model="command-r-plus-08-2024", 7 messages=[{"role": "user", "content": """ 8 You are an expert in data formatting. Convert the following JSON object into a CSV format. 9 10 ``` 11 [ 12 { 13 "name": "Jane Smith", 14 "age": 25, 15 "occupation": "Data Scientist" 16 }, 17 { 18 "name": "Bob Johnson", 19 "age": 42, 20 "occupation": "Software Developer" 21 }, 22 { 23 "name": "Emily Davis", 24 "age": 37, 25 "occupation": "Product Manager" 26 }, 27 ] 28 ``` 29 """}] 30 ) 31 32 print(response.message.content[0].text)