# How to parse JSON values object with numeric key as incrementing time

**URL:** <https://community.influxdata.com/t/how-to-parse-json-values-object-with-numeric-key-as-incrementing-time/30974>\
**Category:** InfluxDB 2\
**Tags:** flux\
**Created:** [August 1, 2023, 2:26pm UTC](https://community.influxdata.com/t/how-to-parse-json-values-object-with-numeric-key-as-incrementing-time/30974 "2023-08-01T14:26:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ib2cool](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ib2cool/32/4949_2.png) [@Ib2cool](https://community.influxdata.com/u/Ib2cool)\
**Post date:** [August 1, 2023, 2:26pm UTC](https://community.influxdata.com/t/how-to-parse-json-values-object-with-numeric-key-as-incrementing-time/30974/1 "2023-08-01T14:26:55Z")

</div>

I have this JSON response that I would like to parse to a flux table:  
`{"body":{"1690727139":[0.059],"1690730739":[0]},"status":"ok"}`  
The body object contains thousands for records.  
Ideally I would do something like:

```auto
foreach ($json->{'body'} as $key => $value) {
  $arr[] = array("_time" => $key, "_value" => $value[0] );
}

```

How can I do this in flux?  
This is my best attempt: (but record.get for every row is not ideal)

```auto
import "array"
import "experimental/json"
import "experimental"
import "experimental/record"
jsonStr = bytes( v: "{\"body\":{\"1690727139\":[0.059],\"1690730739\":[0]},\"status\":\"ok\"}")
data = json.parse(data: jsonStr).body
experimental.objectKeys(o: data)
  |> array.map(fn: (x) => ({_time: time(v: uint(v: string(v: x) + "000000000")), val: display(v: record.get(r: data, key: x, default: [0])[0])}))
  |> array.from()

```

---

<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:** [August 2, 2023, 6:44pm UTC](https://community.influxdata.com/t/how-to-parse-json-values-object-with-numeric-key-as-incrementing-time/30974/2 "2023-08-02T18:44:38Z")

</div>

Hello @Ib2cool,  
Unfortunately without proper looping functionality there isn’t a great way to do this.  
I’m afraid you’ve found the best solution which I agree isn’t great.  
Props for getting some advanced Flux going though.

I would recommend using a client library and a FaaS and pushing the data to InfluxDB once you’ve already parsed it.
