From 6b097a4287b684b384eba9b19e41ed1518ab69fe Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Mon, 8 Jun 2020 17:15:17 -0600 Subject: [PATCH] added experimental json.parse, resolves #1072 --- .../flux/stdlib/experimental/json/_index.md | 23 ++++++++ .../flux/stdlib/experimental/json/parse.md | 53 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 content/v2.0/reference/flux/stdlib/experimental/json/_index.md create mode 100644 content/v2.0/reference/flux/stdlib/experimental/json/parse.md diff --git a/content/v2.0/reference/flux/stdlib/experimental/json/_index.md b/content/v2.0/reference/flux/stdlib/experimental/json/_index.md new file mode 100644 index 000000000..41dcd211b --- /dev/null +++ b/content/v2.0/reference/flux/stdlib/experimental/json/_index.md @@ -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" >}} diff --git a/content/v2.0/reference/flux/stdlib/experimental/json/parse.md b/content/v2.0/reference/flux/stdlib/experimental/json/parse.md new file mode 100644 index 000000000..9a1447d5a --- /dev/null +++ b/content/v2.0/reference/flux/stdlib/experimental/json/parse.md @@ -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"])) +```