Skip to main content
Cohere

Search documentation

Type to search this documentation.

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

Text
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
import cohere

co = cohere.ClientV2(api_key="<YOUR API KEY>")

response = co.chat(
    model="command-a-plus-05-2026",
    messages=[
        {
            "role": "user",
            "content": """
    You are an expert in data formatting. Convert the following JSON object into a 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"
        },
    ]
    ```
    """,
        }
    ],
)

print(response.message.content[0].text)
Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu