# Function JSON-object

**URL:** <https://discuss.kotlinlang.org/t/function-json-object/17767>\
**Category:** Language Design\
**Created:** [May 19, 2020, 6:15pm UTC](https://discuss.kotlinlang.org/t/function-json-object/17767 "2020-05-19T18:15:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![etiennept](https://avatars.discourse-cdn.com/v4/letter/e/7ba0ec/32.png) [@etiennept](https://discuss.kotlinlang.org/u/etiennept)\
**Post date:** [May 19, 2020, 6:15pm UTC](https://discuss.kotlinlang.org/t/function-json-object/17767/1 "2020-05-19T18:15:18Z")

</div>

Does a function exit which returns a JSON-object for a data class

---

<div class="post-metadata">

**Author:** ![tradeJmark](https://avatars.discourse-cdn.com/v4/letter/t/ba9def/32.png) [@tradeJmark](https://discuss.kotlinlang.org/u/tradeJmark)\
**Post date:** [May 19, 2020, 6:44pm UTC](https://discuss.kotlinlang.org/t/function-json-object/17767/2 "2020-05-19T18:44:10Z")

</div>

If you’re asking whether that’s one of the methods auto-generated by making a class a `data class`, then no, it is not. If you’re asking whether there is some extension or static method in the standard library that knows how to convert data classes specifically to JSON, then, also no, because the `data` keyword is not part of the type of a class, or put another way, any method that works for all data class types has to work for all types. There is also no such method that accepts any given type and generates JSON in the non-experimental standard library, so you would probably want to go for a well-established external library, like GSON or Jackson.

---

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [May 19, 2020, 7:25pm UTC](https://discuss.kotlinlang.org/t/function-json-object/17767/4 "2020-05-19T19:25:51Z")

</div>

There are also 2 kotlin libraries that can help with that. One is kotlinx.serialization (still in development but its developed by the kotlin team). The other is called moshi and is an open source library (partially written in kotlin).

Both support generating adapters at compile time (using katp) which is much faster compared to serialization.
