# Webdev return csv

**URL:** <https://forum.inductiveautomation.com/t/webdev-return-csv/71503>\
**Category:** Ignition\
**Created:** [March 23, 2023, 3:38pm UTC](https://forum.inductiveautomation.com/t/webdev-return-csv/71503 "2023-03-23T15:38:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vrautomation](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/vrautomation/32/11155_2.png) [@vrautomation](https://forum.inductiveautomation.com/u/vrautomation)\
**Post date:** [March 23, 2023, 3:38pm UTC](https://forum.inductiveautomation.com/t/webdev-return-csv/71503/1 "2023-03-23T15:38:42Z")

</div>

Simple question,

I'm already using the webdev module to return a json file.

In PowerBI, often it would be much easier to parse a csv. So the question is: is it possible to return a csv instead of a json in a doGet?

Thanks.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 23, 2023, 3:49pm UTC](https://forum.inductiveautomation.com/t/webdev-return-csv/71503/2 "2023-03-23T15:49:49Z")

</div>

Sure, set the `response` key to the CSV text and the `contentType` key to `text/csv`.

[https://docs.inductiveautomation.com/display/DOC81/Web+Dev](https://docs.inductiveautomation.com/display/DOC81/Web+Dev)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 23, 2023, 4:00pm UTC](https://forum.inductiveautomation.com/t/webdev-return-csv/71503/3 "2023-03-23T16:00:30Z")

</div>

If it's a really big CSV, you may want to get to the servlet object directly and stream the results; e.x (this is obviously JSON, but encoding CSV manually is easy enough)

```python
    rows = 20
    columns = xrange(1, 9)
    request["servletResponse"].setContentType("application/json")
    writer = request["servletResponse"].writer

    writer.write("[")
    for i in xrange(rows):
        writer.write(system.util.jsonEncode({'value%d' % j: j for j in columns}))
        if (i < rows - 1):
            writer.write(",")

    writer.write("]")

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 23, 2023, 4:03pm UTC](https://forum.inductiveautomation.com/t/webdev-return-csv/71503/4 "2023-03-23T16:03:41Z")

</div>

I don't think this example is streaming anything because you don't call `flush` at any point.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 23, 2023, 4:07pm UTC](https://forum.inductiveautomation.com/t/webdev-return-csv/71503/5 "2023-03-23T16:07:21Z")

</div>

Ah, good point. You'd probably want to flush every X thousand rows or something. 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![vrautomation](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/vrautomation/32/11155_2.png) [@vrautomation](https://forum.inductiveautomation.com/u/vrautomation)\
**Post date:** [March 23, 2023, 4:16pm UTC](https://forum.inductiveautomation.com/t/webdev-return-csv/71503/6 "2023-03-23T16:16:30Z")

</div>

Thanks to both!

Webdev is really awsome.
