Json value type (label)
Description
Returns the data type of the value inside a JSON object. Note that you must first extract the value from the JSON using the Jq evaluation (jqeval) operation. This operation is helpful when you want to convert the data type of the extracted value and you need to know which one is appropriate.
Alternatively, you can quickly check the data types and transform them even, without previously extracting them, using the pretty-print view (more info in the article Working with JSON objects in data tables).
How does it work in the search window?
Select Create column in the search window toolbar, then select the Json value type operation. You need to specify one argument:
Argument | Data type |
---|---|
Json to get the type (mandatory) | json |
The data type of the values in the new column is string.
Example 1
In this example, we will perform the To json (jsonparse) operation to obtain the JSON below (1) and the Jq evaluation (jqeval) operation to extract one value from it (2):
{"name":"John","birth":"1986-12-14","city":"New York"}
city
After that, we want to know the data type of the extracted value:
Click the Create Column button on the toolbar, select the Json value type (label) operation and give the new column a name.
Add the necessary argument and configure it as shown in the picture below:
Json to get the type → City
Click Create Column and a new column will be created indicating the data type of the city value.
Example 2
In this example, we will perform the To json (jsonparse) operation to obtain the JSON below (1) and the Jq evaluation (jqeval) operation to extract each value in a different column (2):
{"str": "hello", "int": 1, "float": 2.5, "boolean": true, "array": [1,2,3], "object": {"a": 5}}
str, int, float, boolean, array, object
Then, we will use the Json value type (label) operation to get the data type of each value. We will start with the boolean column:
Click the Create Column button on the toolbar, select the Json value type (label) operation and give the new column a name.
Add the necessary argument and configure it as shown in the picture below:
Json to get the type → jsonBoolean
Click Create Column and a new column will be created indicating the data type of the boolean column.
Repeat the same step with all the columns extracted from the JSON and you will get the following result:
How does it work in LINQ?
Use the operator select
... as
... and add the operation syntax to create the new column. This is the syntax for the Json value type operation:
label(json_value)
Example 1
You can use the following LINQ script to recreate example 1 in any table (for example, in demo.ecommerce.data
):
from demo.ecommerce.data
select jsonparse("{ \"name\":\"John\", \"birth\":\"1986-12-14\", \"city\":\"New York\"}") as Json
select jqeval(jqcompile(".city"), Json) as City
select label(City) as CityLabel
Example 2
You can use the following LINQ script to recreate example 2 in any table (for example, in demo.ecommerce.data
):
from demo.ecommerce.data
select jsonparse("{\"str\": \"hola\", \"int\": 1, \"float\": 2.5, \"boolean\": true, \"array\": [1,2,3], \"object\": {\"a\": 5}}") as json
select jqeval(jqcompile(".str"), json) as jsonStr,
jqeval(jqcompile(".int"), json) as jsonInt,
jqeval(jqcompile(".float"), json) as jsonFloat,
jqeval(jqcompile(".boolean"), json) as jsonBoolean,
jqeval(jqcompile(".array"), json) as jsonArray,
jqeval(jqcompile(".object"), json) as jsonObject
select label(jsonStr) as labelStr,
label(jsonInt) as labelInt,
label(jsonFloat) as labelFloat,
label(jsonBoolean) as labelBoolean,
label(jsonArray) as labelArray,
label(jsonObject) as labelObject