added experimental json.parse, resolves #1072
parent
e26a8527f9
commit
6b097a4287
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
title: Flux Experimental JSON package
|
||||
list_title: JSON package
|
||||
description: >
|
||||
The Flux Experimental JSON package provides functions for working with JSON.
|
||||
Import the `experimental/json` package.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: JSON
|
||||
identifier: JSON-exp
|
||||
parent: Experimental
|
||||
weight: 301
|
||||
v2.0/tags: [functions, json, package]
|
||||
---
|
||||
|
||||
Flux JSON functions provide tools for working with Message Queuing Telemetry Transport (JSON) protocol.
|
||||
Import the `experimental/json` package:
|
||||
|
||||
```js
|
||||
import "experimental/json"
|
||||
```
|
||||
|
||||
{{< children type="functions" show="pages" >}}
|
|
@ -0,0 +1,53 @@
|
|||
---
|
||||
title: json.parse() function
|
||||
description: >
|
||||
The `json.parse()` function takes JSON data as bytes and returns a value.
|
||||
menu:
|
||||
v2_0_ref:
|
||||
name: json.parse
|
||||
parent: JSON-exp
|
||||
weight: 401
|
||||
---
|
||||
|
||||
The `json.parse()` function takes JSON data as bytes and returns a value.
|
||||
The function can product lists, objects, strings, booleans, and float values.
|
||||
All numeric values are returned as floats.
|
||||
|
||||
_**Function type:** Type conversion_
|
||||
|
||||
```js
|
||||
import "experimental/json"
|
||||
|
||||
json.parse(
|
||||
data: bytes(v: "{\"\"a\"\":1,\"\"b\"\":2,\"\"c\"\":3}")
|
||||
)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
### data
|
||||
JSON data to parse.
|
||||
|
||||
_**Data type:** Bytes_
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
##### Use JSON data to restructure a table
|
||||
```js
|
||||
import "experimental/json"
|
||||
|
||||
data
|
||||
|> map(fn: (r) => {
|
||||
jsonData = json.parse(data: bytes(v: r._value))
|
||||
|
||||
return {
|
||||
_time: r._time,
|
||||
_field: r._field,
|
||||
a: jsonData.a,
|
||||
b: jsonData.b,
|
||||
c: jsonData.c,
|
||||
}
|
||||
})
|
||||
|> keep(columns: ["_time", "_field", "a", "b", "c"]))
|
||||
```
|
Loading…
Reference in New Issue