Json
Library of functions for JSON data.
Functions
InferAndParse
Reads JSON data from a string with schema detection (inference).
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.
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.
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.
Json.InferAndParse(\"\"\" {"hello" : "world"} \"\"\")
InferAndRead
Reads JSON data from a location with schema detection (inference).
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.
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.
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.
Json.InferAndRead("http://server/file.json")
Parse
Parses JSON data from a string.
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.
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.
Json.Print(expression: anything)
Parameters
expression
: Expression to convert to JSON.
Returns
string
: A JSON string.
Json.Print(Record.Build(name = "john", age = 34))
// Result:
// {"name": "john", "age": 34}
Read
Reads JSON data from a location without schema detection.
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.
let
fileType = type collection(record(name: string, age: int, salary: double))
in
Json.Read("http://server/persons.json", fileType)