# Parse JSON from Flux Query

**URL:** <https://community.influxdata.com/t/parse-json-from-flux-query/26554>\
**Category:** InfluxDB 2\
**Tags:** flux, json\
**Created:** [September 15, 2022, 6:20am UTC](https://community.influxdata.com/t/parse-json-from-flux-query/26554 "2022-09-15T06:20:23Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [September 21, 2022, 3:18pm UTC](https://community.influxdata.com/t/parse-json-from-flux-query/26554/3 "2022-09-21T15:18:09Z")

</div>

Hello @domsch,  
I see that the following works for me:

```auto
import "array"
import "experimental/json"

myJSON = "{\"Results\":[{\"MesswertNr\":4,\"Titel\":\"Spannung\",\"MessschrittNr\":2,\"Min\":30,\"Max\":50,\"Actual\":13},{\"MesswertNr\":5,\"Titel\":\"Strom\",\"MessschrittNr\":2,\"Min\":65,\"Max\":100,\"Actual\":57}]}"

jsonData = json.parse(data: bytes(v: myJSON))
 listData = jsonData.Results

// array.from(rows: [{_value: display(v:listData)}])

 errors = array.map(
      arr: listData,
      fn: (x) => ({
        "MessschrittNr": x.MessschrittNr,
        "MesswertNr": x.MesswertNr,
        "Titel": x.Titel,
        "Min": x.Min,
        "Max": x.Max,
        "Actual": x.Actual,
      })
    )

array.from(rows: errors)

```

I think the issue here is you need a way to name each table stream for each table that’s produced from array.from(). The map function must return an object, not a stream.

Can you share two rows of your original data? Berfore you apply your function in annotated csv please?

I’m not sure how to solve this.  
@scott do you have any ideas?

Here’s an example script to work with:

```auto
import "array"
import "experimental/json"

array.from(rows: [{_value: "{\"Results\":[{\"MesswertNr\":4,\"Titel\":\"Spannung\",\"MessschrittNr\":2,\"Min\":30,\"Max\":50,\"Actual\":13},{\"MesswertNr\":5,\"Titel\":\"Strom\",\"MessschrittNr\":2,\"Min\":65,\"Max\":100,\"Actual\":57}]}"}, {_value: "{\"Results\":[{\"MesswertNr\":4,\"Titel\":\"Spannung\",\"MessschrittNr\":2,\"Min\":30,\"Max\":50,\"Actual\":13},{\"MesswertNr\":5,\"Titel\":\"Strom\",\"MessschrittNr\":2,\"Min\":65,\"Max\":100,\"Actual\":57}]}"}])

 |> map(fn: (r) => {
    jsonData = json.parse(data: bytes(v: r._value)) 
    // extract the list that we want to map across with array.map 
    listData = jsonData.Results
    // map across each complex type in the array named "Results" 
// errors = array.map(
// arr: listData,
// fn: (x) => ({
// "MessschrittNr": x.MessschrittNr,
// "MesswertNr": x.MesswertNr,
// "Titel": x.Titel,
// "Min": x.Min,
// "Max": x.Max,
// "Actual": x.Actual,
// })
// )
// 
// final = array.from(rows: errors) |> group() 
    // finally convert that flattened list into a table with array.from 
    return array.from(rows:[{value: display(v: listData)}]) |> group() 
}

```

---

_[View the full topic](https://community.influxdata.com/t/parse-json-from-flux-query/26554)._
