# Defold Parser | Node module

**URL:** <https://forum.defold.com/t/defold-parser-node-module/71903>\
**Category:** The Defoldmine\
**Created:** [October 19, 2022, 6:43pm UTC](https://forum.defold.com/t/defold-parser-node-module/71903 "2022-10-19T18:43:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Insality](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/insality/32/39737_2.png) [@Insality](https://forum.defold.com/u/Insality)\
**Post date:** [October 19, 2022, 6:43pm UTC](https://forum.defold.com/t/defold-parser-node-module/71903/1 "2022-10-19T18:43:18Z")

</div>

[![image](https://defold-forum-bucket.nbg1.your-objectstorage.com/original/3X/0/3/03fca10ff58c2930b5d2a5a233d55b94d78f53a1.png)](https://github.com/Insality/defold-parser)

_GitHub_: [GitHub - Insality/defold-parser: Node module to encode and decode Defold files · GitHub](https://github.com/Insality/defold-parser)

**Defold Parser** - node module to encode and decode **Defold** files.

There are several tools to parse & edit Defold files like amazing [DefTree](https://forum.defold.com/t/deftree-a-python-module-for-editing-defold-files/15210), but in some cases probably you wanna use the Node/JS. So here is it!

I often use this instrument in my work and I wanna share it with you.

_(still not using Defold proto files)_

## Install

To install **[defold-parser](https://www.npmjs.com/package/defold-parser)** use [`npm`](https://docs.npmjs.com/).

`npm install --save defold-parser`

## Usage

Add require line to your `.js` script:

```js
const defold_parser = require("defold-parser")

```

All available API is:

```js
// Parse any Defold file (go, gui, collection, particlefx, etc)
let object = defold_parser.load_from_file([path_to_defold_file])

// Save object to the Defold format
defold_parser.save_to_file([path_to_file], [object])

// You can pass text string directly
let object = defold_parser.decode_object([defold_text_string])

// And get Defold encoded text directly too
let defold_text_string = defold_parser.encode_object([js_object])

```

Every **Defold** parsed struct is array, even for single fields. To access any field you should access it on first array index. For example:

```js
let parsed_collection = defold_parser.load_from_file("./tests/files/collection.collection")
let instance = parsed_collection.embedded_instances[0]

assert(instance.id[0] == "tile")
assert(inner_component.id[0] = "sprite")
assert(inner_component.type[0] = "sprite")

```

To know, which fields you wanna edit, see the file struct you parsing or just use `console.log` in development 😄
