Skip to main content

Json

Library of functions for JSON data.

Functions

InferAndParse

Reads JSON data from a string with schema detection (inference).

Syntax:
Json.InferAndParse(stringData: string, sampleSize: optional int, encoding: optional string, preferNulls: optional bool)
Parameters
  • stringData: The data in string format to infer and parsed.

  • sampleSize: Specifies the number of objects to sample within the data.

note

If a large sampleSize is used, the detection takes more time to complete, but has a higher chance of detecting the correct format. To force the detection to read the full data, set sampleSize to -1.

  • encoding: Specifies the encoding of the data.
note

If the encoding is not specified it is determined automatically.

  • preferNulls: If set to true and during inference the system does read the whole data, marks all fields as nullable. Defaults to true.
Example:
Json.InferAndParse(\"\"\" {"hello" : "world"} \"\"\")

InferAndRead

Reads JSON data from a location with schema detection (inference).

Syntax:
Json.InferAndRead(location: location or string, sampleSize: optional int, encoding: optional string, preferNulls: optional bool)
Parameters
  • location: The location or url of the data to read.

  • sampleSize: Specifies the number of objects to sample within the data.

note

If a large sampleSize is used, the detection takes more time to complete, but has a higher chance of detecting the correct format. To force the detection to read the full data, set sampleSize to -1.

  • encoding: Specifies the encoding of the data.
note

If the encoding is not specified it is determined automatically.

  • preferNulls: If set to true and during inference the system does read the whole data, marks all fields as nullable. Defaults to true.
Example:
Json.InferAndRead("http://server/file.json")

Parse

Parses JSON data from a string.

Syntax:
Json.Parse(string: string, type: type, timeFormat: optional string, dateFormat: optional string, timestampFormat: optional string)
Parameters
  • string: The string containing the JSON to parse.

  • type: The type of the data in the JSON.

  • timeFormat: Specifies the format to parse time fields. Defaults to "HH:mm[:ss[.SSS]]".

  • dateFormat: Specifies the format to parse date fields. Defaults to "yyyy-M-d".

  • timestampFormat: Specifies the format to parse timestamp fields. Defaults to "yyyy-M-d['T'][ ]HH:mm[:ss[.SSS]]".

Returns
  • The data parsed from the JSON string.
Example:
let
dataType = type collection(record(name: string, age: int, salary: double)),
data = """ [
{"name": "john", "age": 34, ""salary: 14.6},
{"name": "jane", "age": 32, ""salary: 15.8},
{"name": "Bob", "age": 25, ""salary: 12.9}
] """
in
Json.Parse(data, dataType)

Print

Converts an expression to a JSON string.

Syntax:
Json.Print(expression: anything)
Parameters
  • expression: Expression to convert to JSON.
Returns
  • string: A JSON string.
Example:
Json.Print(Record.Build(name = "john", age = 34))
// Result:
// {"name": "john", "age": 34}

Read

Reads JSON data from a location without schema detection.

Syntax:
Json.Read(location: location or string, type: type, encoding: optional string, timeFormat: optional string, dateFormat: optional string, timestampFormat: optional string)
Parameters
  • location: The location or url of the data to read.

  • type: The type of the data in the JSON.

  • encoding: Specifies the encoding of the data. Defaults to "utf-8".

  • timeFormat: Specifies the format to parse time fields. Defaults to "HH:mm[:ss[.SSS]]".

  • dateFormat: Specifies the format to parse date fields. Defaults to "yyyy-M-d".

  • timestampFormat: Specifies the format to parse timestamp fields. Defaults to "yyyy-M-d['T'][ ]HH:mm[:ss[.SSS]]".

Returns
  • The data read from the JSON file.
Example:
let
fileType = type collection(record(name: string, age: int, salary: double))
in
Json.Read("http://server/persons.json", fileType)