# Javascript structure representation using Kotlin JS

**URL:** <https://discuss.kotlinlang.org/t/javascript-structure-representation-using-kotlin-js/17422>\
**Category:** JavaScript\
**Created:** [April 30, 2020, 8:44am UTC](https://discuss.kotlinlang.org/t/javascript-structure-representation-using-kotlin-js/17422 "2020-04-30T08:44:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![corzani](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/corzani/32/7484_2.png) [@corzani](https://discuss.kotlinlang.org/u/corzani)\
**Post date:** [April 30, 2020, 8:44am UTC](https://discuss.kotlinlang.org/t/javascript-structure-representation-using-kotlin-js/17422/1 "2020-04-30T08:44:26Z")

</div>

my question is about creating javascript structure within KotlinJS and use them calling external modules. Let’s say we have the following js code and we want to translate it into KotlinJS.

```auto
const config = {
defs : "something",
resolvers : {
  Query: {
    books: () => []
  }}
};

myFunction(config) // This can be any kind of external js function that accepts the above structure

```

How do we represent that config structure above using Kotlin JS? Is there an easy way to handle structures/json Kotlin side? Can we declare in some way that structure as dynamic?

---

<div class="post-metadata">

**Author:** ![corzani](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/corzani/32/7484_2.png) [@corzani](https://discuss.kotlinlang.org/u/corzani)\
**Post date:** [May 4, 2020, 5:08pm UTC](https://discuss.kotlinlang.org/t/javascript-structure-representation-using-kotlin-js/17422/2 "2020-05-04T17:08:37Z")

</div>

**This answer comes from one of the Dukat authors @shabunc**

As of now you gotta introduce interface and it’s implementation, so it would be something like this:

```auto
external interface ConfigInterface {
  var defs: String,
  var resolvers: QueryHolder
}

external interface QueryHolder {
   var Query: BookProcessor
}

external interface BookProcessor {
   var books: () -> Array<Any>
}

```

For more complicated structures it can easily become a challenge. Here’s what can be done to automate such translations. You can:

- generate typescript declaration for this code with typescript compiler (using `tsc -d` )
- generate kotlin declaration with [dukat](https://www.npmjs.com/package/dukat).

Dukat is a tool from Kotlin/JS team created specifically for this, there’s [ongoing battle](https://github.com/Kotlin/dukat/issues) for improving the quality of this tool. Here is what would be generated in your particular case:

```auto
external interface `T$0` {
    var books: () -> Array<Any>
}

external interface `T$1` {
    var Query: `T$0`
}

external object config {
    var defs: String
    var resolvers: `T$1`
}

```

Which is far from optimal - for instance the name of generated entities is something we didn’t wanted to encourage people to reuse but the more it goes, the more it looks like a mistake (which we will fix this way or another).
