IsJson  - 脚本和图表功能
                IsJson() 测试指定字符串是否包含有效的 JSON(JavaScript 对象表示法)数据。您还可以验证特定的 JSON 数据类型。 
                语法:  
                value IsJson(json [, type]) 
                返回数据类型:  双
                
                    参数
                    
                    
                    
                        
                    
                    
                        
                            | 
                                json
                             | 
                            要测试的字符串。它可以包含额外的空格或换行符。 | 
                        
                        
                            | 
                                type
                             | 
                            
                                 可选参数,指定要测试的 JSON 数据类型。 
                                
                                    - 
                                        
'value'(默认值) 
                                     
                                    - 
                                        
'object' 
                                     
                                    - 
                                        
'array' 
                                     
                                    - 
                                        
'string' 
                                     
                                    - 
                                        
'number' 
                                     
                                    - 
                                        
'Boolean' 
                                     
                                    - 
                                        
'null'  
                                     
                                 
                             | 
                        
                    
                
 
                
                    示例:有效和无效的图表表达式
                    
                    
                    
                        
                    
                    
                        
                            | IsJson( 'null' )
                             | 
                            返回 -1 (true) | 
                        
                        
                            | IsJson( '"abc"', 'value' )
                             | 
                            返回 -1 (true) | 
                        
                        
                            | IsJson( '"abc"', 'string' )
                             | 
                            返回 -1 (true) | 
                        
                        
                            | IsJson( 123, 'number' )
                             | 
                            返回 -1 (true) | 
                        
                        
                            | IsJson( 'text' )
                             | 
                            返回的 0 (false)、'text' 不是有效  JSON 值。 | 
                        
                        
                            | IsJson( '"text"', 'number' )
                             | 
                            返回的 0 (false)、'"text"' 不是有效  JSON 数字。 | 
                        
                        
                            | IsJson( '"text"', 'text' )
                             | 
                            返回的  0 (false)、'text' 不是有效  JSON 类型。 | 
                        
                    
                
  示例 - IsJson 基本原理
概述
打开数据加载编辑器,并将下面的加载脚本添加到新部分。 
加载脚本包含:
加载脚本
Example:
Load
Recno() AS ID, API_Response
inline [
API_Response
'{"id": 1, "name": "Alice"}'
'{"id": 2, "name": "Bob"}'
'{invalid json string}'
'{"id": 4, "name": "Charlie"}'
'{"id": 5, name: "David"}'
];
结果
加载数据并打开工作表。创建新表并将这些字段添加为维度:
创建以下计算维度:
结果表  | ID | API_Response | IsJson(API_Response) | 
|---|
| 1 | {"id": 1, "name": "Alice"} | -1 (true) | 
| 2 | {"id": 2, "name": "Bob"} | -1 (true) | 
| 3 | {invalid json string} | 0 (false) | 
| 4 | {"id": 4, "name": "Charlie"} | -1 (true) | 
| 5 | {"id": 5, name: "David"} | 0 (false) | 
对于具备有效 JSON 语法的值,输出返回 -1 或 true。
对于以下具有无效 JSON 的ID记录(3 和 5),输出返回 0 或 false:
示例 - IsJson 场景
概述
打开数据加载编辑器,并将下面的加载脚本添加到新部分。 
加载脚本包含:
加载脚本
Example:
Load *
INLINE [OrderDetails
'{ "order_id": "12345", "customer": { "name": "John Doe", "email": "john.doe@example.com"}, "items": {"product": "Laptop", "quantity": 2, "price": 1200 }, "total_price": 2400 }'
];
结果
加载数据并打开工作表。创建新表并将该字段添加为维度:
创建以下度量:
IsJson( OrderDetails),用来计算 OrderDetails 中的值是否为有效 JSON。 
IsJson( JsonGet ( OrderDetails, '/items/price' ), 'number' ),使用该函数 JsonGet,它检索 price 键的 JSON 文本,并验证的 price 值是否为数字。
结果表  | OrderDetails | IsJson(OrderDetails) | IsJson( JsonGet ( OrderDetails, '/items/price' ), 'number' ) | 
|---|
| { "order_id": "12345", "customer": { "name": "John Doe", "email": "john.doe@example.com"}, "items": {"product": "Laptop", "quantity": 2, "price": 1200 }, "total_price": 2400 }  | -1 (true) | -1 (true) | 
第一个度量返回 -1 (true),因为 OrderDetails 包含有效的 JSON 语法。
第二个度量返回 -1 (true),因为 price 键的值是一个有效数字 1200 。
另请参阅: