JsonArray - 指令碼與圖表函數
JsonArray 彙總並串連 JSON 資料。
語法:
JsonArray([DISTINCT][TOTAL] value [, sort_weight])
傳回的資料類型: 雙值
引數:
| 引數 | 描述 | 
|---|---|
| DISTINCT | 如果 DISTINCT 這個字出現在函數引數之前,會忽略評估函數引數所產生的重複項目。 | 
| TOTAL | 如果單字 TOTAL 位於函數引數之前,則會在提供現行選項的所有可能值上進行計算,而不僅僅是關於目前維度值的那些選項,也就是說,它會忽略圖表維度。 | 
| value | 輸入欄位。 包含待排序之資料的運算式。會找到 sort_weight 的第一個 (最低) 值,從中判定 value 運算式的對應值。如果您在 sort_weight 前面放置一個負號,則該函數會改為傳回最後一個 (最高) 的已排序值。 | 
| sort_weight | 輸入欄位。 包含待排序之資料的運算式。會找到 sort_weight 的第一個 (最低) 值,從中判定 value 運算式的對應值。如果您在 sort_weight 前面放置一個負號,則該函數會改為傳回最後一個 (最高) 的已排序值。 | 
範例:
以下載入指令碼使用 JsonArray 載入和彙總資料。
Data:
LOAD Id,
	JsonArray(ValueOrNull) AS Json,
	JsonArray(DISTINCT ValueOrNull) AS JsonDistinct,
	JsonArray(ValueOrNull, Order) AS JsonSorted
GROUP BY Id;
LOAD *, If(Value='-',Null(),Value) AS ValueOrNull;
LOAD * INLINE '
	Id | Value          | Order
	1  | 123            | 1
	2  | "json text"    | 2
	2  | normal text    | 1
	3  | [1,2,3]        | 3
	3  | {"name":"abc"} | 2
	3  | [1,2,3]        | 1
	4  | 1              | 1
	4  | 2 and text     | 2
	4  |                | 3
	4  | -              | 4
	' (delimiter is '|');
                這會產生以下資料表格:
| Id | Json | JsonDistinct | JsonSorted | 
|---|---|---|---|
| 1 | [123] | [123] | [123] | 
| 2 | ["json text","normal text"] | ["json text","normal text"] | ["normal text","json text"] | 
| 3 | [[1,2,3],[1,2,3],{"name":"abc"}] | [[1,2,3],{"name":"abc"}] | [[1,2,3],{"name":"abc"},[1,2,3]] | 
| 4 | [1,"2 and text",""] | [1,"2 and text",""] | [1,"2 and text",""] |