# Interpreting JSON data

**URL:** <https://community.smartthings.com/t/interpreting-json-data/159960>\
**Category:** Writing SmartApps\
**Created:** [April 4, 2019, 9:20am UTC](https://community.smartthings.com/t/interpreting-json-data/159960 "2019-04-04T09:20:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Wallace](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/jason_wallace/32/90992_2.png) [@Jason\_Wallace](https://community.smartthings.com/u/Jason_Wallace)\
**Post date:** [April 4, 2019, 9:20am UTC](https://community.smartthings.com/t/interpreting-json-data/159960/1 "2019-04-04T09:20:30Z")

</div>

Hi there folks

I’m ashamed to be posting such a Noob question so apologies in advance.

I am trying to get some data from an API and present it in SmartThings. What _should_ be easy is proving to be anything but for my limited coding ability.

I’m making a call to [https://api.carbonintensity.org.uk/regional/postcode/GL51](https://api.carbonintensity.org.uk/regional/postcode/GL51) in order to dig out the real-time energy intensity of power generation in my area of the UK. This returns:

{“data”:[{“regionid”:7,“dnoregion”:“WPD West Midlands”,“shortname”:“West Midlands”,“postcode”:“GL51”,“data”:[{“from”:“2019-04-03T17:00Z”,“to”:“2019-04-03T17:30Z”,“intensity”:{“forecast”:279,“index”:“high”},“generationmix”:[{“fuel”:“biomass”,“perc”:3.8},{“fuel”:“coal”,“perc”:5.9},{“fuel”:“imports”,“perc”:0.2},{“fuel”:“gas”,“perc”:55.4},{“fuel”:“nuclear”,“perc”:3.9},{“fuel”:“other”,“perc”:0},{“fuel”:“hydro”,“perc”:6.6},{“fuel”:“solar”,“perc”:3.7},{“fuel”:“wind”,“perc”:20.5}]}]}]}

which is all very pretty and contains EXACTLY what I want.

Some time ago I wrote a WebCORE piece of code and was interested in the index value at the time. I simply wanted to control some switches to come on when carbon intensity is LOW or VERY LOW. In WebCORE I used $response.data.data.intensity.index and this did the trick.

In SmartApp I added:

log.debug “response data: {resp.data}" log.debug "intensity index: {resp.data.data.intensity.index}”

but I get:

98cfdccc-a158-42b2-adc9-49d2d609c8bf 10:18:01: debug intensity index:   
98cfdccc-a158-42b2-adc9-49d2d609c8bf 10:18:01: debug response data: [data:[[data:[[from:2019-04-04T08:30Z, generationmix:[[fuel:biomass, perc:3.4], [fuel:coal, perc:5.2], [fuel:imports, perc:0.8], [fuel:gas, perc:51.8], [fuel:nuclear, perc:11.3], [fuel:other, perc:0], [fuel:hydro, perc:7.8], [fuel:solar, perc:1.6], [fuel:wind, perc:18.1]], intensity:[forecast:256, index:moderate], to:2019-04-04T09:00Z]], dnoregion:WPD West Midlands, postcode:GL51, regionid:7, shortname:West Midlands]]]

How can I start breaking this data out in a way that I can use?

TIA

---

<div class="post-metadata">

**Author:** ![ritchierich](https://avatars.discourse-cdn.com/v4/letter/r/a4c791/32.png) [@ritchierich](https://community.smartthings.com/u/ritchierich)\
**Post date:** [April 4, 2019, 11:56am UTC](https://community.smartthings.com/t/interpreting-json-data/159960/2 "2019-04-04T11:56:11Z")

</div>

Use JsonSlurper(). You can search Google for examples. Here is another thread with details too:

> [@Help Searching a JsonSlurper list](https://community.smartthings.com/t/help-searching-a-jsonslurper-list/20909?source_topic_id=92636):
>
> I’m trying to parse out the following json string: {"cid":"PWER","data":[{"1440023704000":0}],"sid":"123456","units":"kWm","age":142156},{"cid":"PWER\_GAC","data":[{"1440165858000":2202}],"sid":"123456","units":null,"age":2} Here is the code snip i’m using: def respData = summaryResp.data.text log.debug "Summary Reading Result: $summaryResp.data" log.debug "Summary text: ${respData}" def list = new JsonSlurper().parseText(respData) def cids = list.cid log.debug "Cid List: $cids" log.debug "List Values: $list" if(list.cid == "PWER\_GAC" && list.age \<= 10) clampType = "PWER\_GAC" log.debug "PWER\_GAC Data ${list.data}" log.debug "PWER\_GAC TimeStamp: ${list.data}" log.debug "PWER\_GAC Reading: ${list.data}" if(list.cid == "PWER" && list.age \<= 10) clampType = "PWER" …

---

<div class="post-metadata">

**Author:** ![Jason\_Wallace](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/jason_wallace/32/90992_2.png) [@Jason\_Wallace](https://community.smartthings.com/u/Jason_Wallace)\
**Post date:** [April 4, 2019, 12:19pm UTC](https://community.smartthings.com/t/interpreting-json-data/159960/3 "2019-04-04T12:19:04Z")

</div>

Thanks very much.

‘‘Twas late last night and I thought that I had Googled 🙂
