# Accessing JSON fields

**URL:** <https://forum.flowable.org/t/accessing-json-fields/1329>\
**Category:** Flowable Application\
**Created:** [December 13, 2017, 9:24am UTC](https://forum.flowable.org/t/accessing-json-fields/1329 "2017-12-13T09:24:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![clara.gaset](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@clara.gaset](https://forum.flowable.org/u/clara.gaset)\
**Post date:** [December 13, 2017, 9:24am UTC](https://forum.flowable.org/t/accessing-json-fields/1329/1 "2017-12-13T09:24:23Z")

</div>

Hi,  
I’ve implemented an HTTP task and I’m showing the JSON result in a form using an expression field. My problem is that I don’t know how to access the values instead of showing the whole response.

The response is similiar to this:

> {  
> “data”: [
> 
> ```
> {
> "id": "admin",
> "name": "Test",
> },
> {
> "id": "superAdmin",
> "name": "superAdmin",
> }
> 
> ```
> 
> ],  
> “total”: 2  
> }

To see the respone I wrote ${myVar} where myVar is the name I placed in the field “Response varaible name” in HTTP task properties.  
My tests where ${myVar}.total and ${myVar.total} but none worked.

Anyone knows if it’s possible to show only “total” value?

Thanks

---

<div class="post-metadata">

**Author:** ![arpit.agrawal](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@arpit.agrawal](https://forum.flowable.org/u/arpit.agrawal)\
**Post date:** [December 13, 2017, 9:20pm UTC](https://forum.flowable.org/t/accessing-json-fields/1329/2 "2017-12-13T21:20:14Z")

</div>

Hi,

I think the response from API is stored as TEXT in the database. So you cannot directly access the key as its not JSON when you retrieve it from processVariable but a string. You can use something like

import org.flowable.engine.impl.util.json.JSONObject;  
JSONObject response = new JSONObject(“String version of your processVariable”);  
then do  
response.getInt(“total”) to get the value of the total key.

You can expore all other methods to access data from response in JSONObject class.

Hope this helps.

Thank You,  
Arpit

---

<div class="post-metadata">

**Author:** ![Pau](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/pau/32/1673_2.png) [@Pau](https://forum.flowable.org/u/Pau)\
**Post date:** [March 17, 2020, 1:50pm UTC](https://forum.flowable.org/t/accessing-json-fields/1329/3 "2020-03-17T13:50:09Z")

</div>

Sorry in which file should we include these lines? Thanks!

---

<div class="post-metadata">

**Author:** ![jrautner](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrautner](https://forum.flowable.org/u/jrautner)\
**Post date:** [April 3, 2020, 2:09pm UTC](https://forum.flowable.org/t/accessing-json-fields/1329/4 "2020-04-03T14:09:29Z")

</div>

Hi Pau,

I’m accessing data from http request in variable resp (name is defined in http task) for example in javascript script task.

var resp = execution.getVariable(‘resp’);  
var response = JSON.parse(resp);  
execution.setVariable(‘resp\_total’, response.total);

---

<div class="post-metadata">

**Author:** ![prasanta](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/prasanta/32/2864_2.png) [@prasanta](https://forum.flowable.org/u/prasanta)\
**Post date:** [January 4, 2023, 6:15am UTC](https://forum.flowable.org/t/accessing-json-fields/1329/5 "2023-01-04T06:15:45Z")

</div>

Hi,  
I facing similar issue what you mentioned here. In below script I have a question.

var resp = execution.getVariable(‘resp’);  
var response = JSON.parse(resp);  
execution.setVariable(‘resp\_total’, response.total);

If resp is json type then you don’t need to do parse. Right?
