# Select single value from payload

**URL:** <https://forums.losant.com/t/select-single-value-from-payload/4252>\
**Category:** Help\
**Tags:** function\
**Created:** [December 5, 2021, 6:11am UTC](https://forums.losant.com/t/select-single-value-from-payload/4252 "2021-12-05T06:11:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Felice\_Massaro](https://avatars.discourse-cdn.com/v4/letter/f/c2a13f/32.png) [@Felice\_Massaro](https://forums.losant.com/u/Felice_Massaro)\
**Post date:** [December 5, 2021, 6:11am UTC](https://forums.losant.com/t/select-single-value-from-payload/4252/1 "2021-12-05T06:11:57Z")

</div>

I am not a coder but I challenge myself. I am attempting to select only a specific value from a payload.  
this is my payload:

```auto
{
  "applicationId": "61ac43d686ea5501fd13a215",
  "applicationName": "Sigfox callback",
  "data": {
    "body": {
      "{ \"device\" : \"2058EE\", \"time\" : \"1638684238\", \"data\" : \"5af3107a1d47\", \"seqNumber\" : \"48\" }": ""
    },
    "headers": {
      "accept-charset": "UTF-8;q=0.9,*;q=0.7",
      "accept-encoding": "gzip,deflate",
      "accept-language": "fr",
      "content-length": "150",
      "content-type": "application/x-www-form-urlencoded",
      "user-agent": "SIGFOX",
      "x-forwarded-for": "185.110.98.5",
      "x-forwarded-proto": "https",
      "x-real-ip": "185.110.98.5"
    },
    "method": "post",
    "path": "/",
    "query": {
    },
    "replyId": "61ac441b09119443483690b9.ncLGvXeJe5koM4xW7skVg.uacZ7klp0W6vpw_EOygbgW"
  },
  "flowId": "61ac47e18c09256f92188669",
  "flowName": "Sigfox1",
  "flowVersion": "develop",
  "globals": {
  },
  "relayId": "000000000000000000000000",
  "relayType": "public",
  "time": "2021-12-05T06:05:10.491Z",
  "triggerId": "61ac441b09119443483690b9",
  "triggerType": "webhook"
}

```

I am trying to select and output only the value "data"in the body.  
I have tried with a function on this way:

```auto
payload = payload.data.body.data

```

but I am not coming right. I can output the entire string “body”: {  
“{ “device” : “2058EE”, “time” : “1638762361”, “data” : “5af3107a1d47”, “seqNumber” : “61” }”: “”  
}

```auto
payload = payload.data.body
return payload;

```

But I am battling to get only the string data in body.  
How can I extract only the value in data?  
Thanks for helping

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [December 6, 2021, 2:17pm UTC](https://forums.losant.com/t/select-single-value-from-payload/4252/2 "2021-12-06T14:17:46Z")

</div>

Hey @Felice_Massaro,

Welcome to the Losant forums, we’re happy to have you!

Your payload path looks correct, but the issue is that your `body` value in your payload is not JSON, it is just a string that looks like JSON. You should include a [JSON: Decode Node](https://docs.losant.com/workflows/logic/json-decode/) before the Function Node to turn that string into a JSON Object.

Also, a small note, it looks like `data.body` may not be valid JSON with the format you’ve sent. Are you able to change the incoming data?

Thank you,  
Heath

---

<div class="post-metadata">

**Author:** ![Felice\_Massaro](https://avatars.discourse-cdn.com/v4/letter/f/c2a13f/32.png) [@Felice\_Massaro](https://forums.losant.com/u/Felice_Massaro)\
**Post date:** [December 6, 2021, 3:59pm UTC](https://forums.losant.com/t/select-single-value-from-payload/4252/3 "2021-12-06T15:59:19Z")

</div>

@Heath Thank you for your warm welcome.

The body of the callback I have in the Sigfox backend was autogenerated when I defined the keys in the device:

```auto
{
  "device" : "{device}",
  "time" : "{time}",
  "data" : "{data}",
  "seqNumber" : "{seqNumber}"
}

```

About the decode node. I see that a path to the payload and to the destination load is needed. Where do I find those paths?

Yes I can change the body of the callback but I am not sure if it will comply with Sigfox. The above one is working.  
Thank you for helping

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [December 6, 2021, 4:13pm UTC](https://forums.losant.com/t/select-single-value-from-payload/4252/4 "2021-12-06T16:13:50Z")

</div>

@Felice_Massaro

> I see that a path to the payload and to the destination load is needed. Where do I find those paths?

The destination path is anywhere on the payload where you want the output to be placed. So, for example, if you wanted the decoded JSON value to be placed back at the place where it came in, your node configuration would look like this:

![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/1/1090e7ed7fa71fa06aedf3ab2797b500b28c8522.png)

But, our best practice is to put new/mutated values in a new path, like `working`. That would look like this:

![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/4/43acfc8771259867e5ca97df18cfe78073f2d7c1.png)

When placing an output of a node at a **new** payload path that doesn’t exist yet, Losant automatically makes that new path for you.

Let me know if this works for you, or if you need any more information on anything!

Thank you,  
Heath

---

<div class="post-metadata">

**Author:** ![Felice\_Massaro](https://avatars.discourse-cdn.com/v4/letter/f/c2a13f/32.png) [@Felice\_Massaro](https://forums.losant.com/u/Felice_Massaro)\
**Post date:** [December 6, 2021, 4:23pm UTC](https://forums.losant.com/t/select-single-value-from-payload/4252/5 "2021-12-06T16:23:26Z")

</div>

I did try but no luck! I am not sure about what I am doing wrong. I did use the path as per your second example data.body \>\>\> working .body  
But I am now getting " **InvalidJsonError** Source did not contain valid JSON: data.body"

CORRECTION  
The error message from the decode node is: Source did not contain valid JSON: data.body

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [December 6, 2021, 5:16pm UTC](https://forums.losant.com/t/select-single-value-from-payload/4252/6 "2021-12-06T17:16:24Z")

</div>

@Felice_Massaro,

As I mentioned in my first reply, what you’re sending along via SigFox is **not** valid JSON. What’s happening is that you are receiving a JSON String as an Object Key where the value is an empty string (`""`).

If you are unable to edit the incoming body of the request, you will need to use an [Object Node](https://docs.losant.com/workflows/logic/object/) with the `Keys` operation. Then you can use the JSON: Decode node to decode that JSON String that is created.

I’ve attached a sample workflow that shows this process using the exact body of your payload in the Virtual Button. [How to import a workflow](https://docs.losant.com/workflows/overview/#import--export).

[decode-develop.flow](https://forums.losant.com/uploads/short-url/bPyNoEyGaY1rd4waqBI39aHPW81.flow) (2.2 KB)

Let me know if this works for you!

Heath

---

<div class="post-metadata">

**Author:** ![Felice\_Massaro](https://avatars.discourse-cdn.com/v4/letter/f/c2a13f/32.png) [@Felice\_Massaro](https://forums.losant.com/u/Felice_Massaro)\
**Post date:** [December 6, 2021, 6:06pm UTC](https://forums.losant.com/t/select-single-value-from-payload/4252/7 "2021-12-06T18:06:38Z")

</div>

Sorry to abuse you. How would you change the incoming body? I am willing to try on that side.  
As I mentioned in my first post, I am not a coder so during the learning process … I need some help.  
Thanks

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [December 6, 2021, 7:34pm UTC](https://forums.losant.com/t/select-single-value-from-payload/4252/8 "2021-12-06T19:34:49Z")

</div>

@Felice_Massaro,

From the looks of it, I assumed you were using a SigFox device and are able to choose what SigFox sends when it invokes the Webhook trigger as [this blog post](https://www.losant.com/blog/collect-monitor-visualize-sigfox-data) (which is a bit old) suggests.

Is this the correct assumption? How is the webhook trigger being triggered?

Heath

---

<div class="post-metadata">

**Author:** ![Felice\_Massaro](https://avatars.discourse-cdn.com/v4/letter/f/c2a13f/32.png) [@Felice\_Massaro](https://forums.losant.com/u/Felice_Massaro)\
**Post date:** [December 7, 2021, 4:54am UTC](https://forums.losant.com/t/select-single-value-from-payload/4252/9 "2021-12-07T04:54:42Z")

</div>

Bingo!. It now works perfectly.  
I have used your flow replacing the button with my webhook and added a function after the Json decode node as following:

```auto
payload = payload.working.decoded.data;

```

finally I get the value I was looking for.  
Thanks a million for your help and extra help.
