# Getting "Decoder not valid: does not return an object"

**URL:** <https://www.thethingsnetwork.org/forum/t/getting-decoder-not-valid-does-not-return-an-object/13937>\
**Category:** Application Development\
**Created:** [May 5, 2018, 5:32am UTC](https://www.thethingsnetwork.org/forum/t/getting-decoder-not-valid-does-not-return-an-object/13937 "2018-05-05T05:32:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![smbunn](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/smbunn/32/47939_2.png) [@smbunn](https://www.thethingsnetwork.org/forum/u/smbunn)\
**Post date:** [May 5, 2018, 5:32am UTC](https://www.thethingsnetwork.org/forum/t/getting-decoder-not-valid-does-not-return-an-object/13937/1 "2018-05-05T05:32:15Z")

</div>

I have data arriving in my application and can see the payload is correct as a series of hex bytes (actually just the string “Hello World”.plus the counter. All good. Now how do I decode the payload in the application console?  
I though that ‘payload formats’ sounding encouraging. I added some javascript to this and saved it.

```javascript
function Decoder(bytes, port) {
  // Decode plain text; not recommended 
  return String.fromCharCode.apply(null, bytes);
}

```

Nothing happened. is something supposed to happen? Am I supposed to see the decoded payload when I click on the data tab?

This all worked with AWS IoT and LORIOT, but I was surprised to see this does not seem to do anything in TTN? What am I missing here?

When I paste in a payload from the data arriving and hit test it says:

```nohighlight
Error("Decoder not valid: does not return an object")

```

thanks

Simon

---

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [May 5, 2018, 9:27am UTC](https://www.thethingsnetwork.org/forum/t/getting-decoder-not-valid-does-not-return-an-object/13937/2 "2018-05-05T09:27:52Z")

</div>

A JavaScript object has property names and values, like:

```javascript
{
  myText: 'Hello world',
  myNumber: -3,
  myOtherNumber: 42,
  myNestedObject: {
    a: 1,
    b: 2,
    c: true
  }
}

```

Decoders in TTN Console must return an object. But your decoder only returns a single text value, without a name. So, for your test, you’d need something like:

```javascript
function Decoder(bytes, port) {
  return {
    // Decode plain text; for testing only
    myValue: String.fromCharCode.apply(null, bytes)
  };
}

```

This might seem useless for just a single value, but is very useful for multiple values:

```javascript
function Decoder(bytes, port) {
  return {
    // Decode plain text; for testing only
    myValue: String.fromCharCode.apply(null, bytes),
    port: port
  };
}

```

(Again, the above is not quite useful, but a true decoder might decode a single payload into multiple values.)

As an aside, the above is the same as:

```javascript
function Decoder(bytes, port) {
  var decoded = {};
  // Decode plain text; for testing only
  decoded.myValue = String.fromCharCode.apply(null, bytes);
  decoded.port = port;
  return decoded;
}

```

See also [Is there any documentation on payload functions?](https://www.thethingsnetwork.org/forum/t/is-there-any-documentation-on-payload-functions/3441/3)

(And: [don’t send text](https://www.thethingsnetwork.org/forum/t/best-practices-to-limit-application-payloads/1302).)
