JSONPath:使用键和值提取单个dict

JSONPath:使用键和值提取单个dict,json,jsonpath,azure-data-lake,u-sql,Json,Jsonpath,Azure Data Lake,U Sql,我有一个在Azure Data Lake环境中运行的U-SQL应用程序。它应该处理一个充满JSON数据的文件,看起来像这样,除了在现实生活中远远超过两行之外 [ {"reports" : {"direction": "FWD", "drive": "STOPS", "frob_variable": 0}}, {"reports" : {"direction": "FWD", "drive": "CRANKS", "frob_variable": -3}} ] 在Data Lake的工作中,我有

我有一个在Azure Data Lake环境中运行的U-SQL应用程序。它应该处理一个充满JSON数据的文件,看起来像这样,除了在现实生活中远远超过两行之外

[
{"reports" : {"direction": "FWD", "drive": "STOPS", "frob_variable": 0}},
{"reports" : {"direction": "FWD", "drive": "CRANKS", "frob_variable": -3}}
]
在Data Lake的工作中,我有以下几行:

@json =
EXTRACT direction string, drive string, frob_variable int FROM @"/input/file.json"
USING new Microsoft.Analytics.Samples.Formats.Json.JsonExtractor("reports");
当我将
@json
变量的内容转储到文本文件时,我得到的是空值:零长度字符串和零值整数。不过,我确实获得了正确的输出行数,因此它必须迭代所有输入

在源代码中搜索一下
JsonExtractor
就会发现,我指定的JsonPath值(“reports”)似乎正在返回带有嵌入dict的“reports”键。如果我尝试将JsonPath值设置为“reports.*”我会得到嵌入值(例如,
{“FWD”,“STOPS”,0}
)但我真的很想让这些键与它们一起使用,这样
选择方向、驱动、frob_变量
将返回一些有用的信息

长话短说,我正在寻找一种从内部dict中提取键和值的方法。因此,
EXTRACT
的理想输出将是一个行集,其列为“direction”、“drive”和“frob_variable”,其值如源数据所示。在U-SQL中似乎应该有一个JsonPath解决方案或一个简单的解决方法

@extract =
     EXTRACT 
         reports String
     FROM @"/input/file.json"
     USING new Microsoft.Analytics.Samples.Formats.Json.JsonExtractor();

@relation =
    SELECT
     Microsoft.Analytics.Samples.Formats.Json.JsonFunctions.JsonTuple(reports)
     AS report
    FROM @extract;

@fields =
    SELECT 
       report["direction"] AS direction,
       report["drive"] AS drive,
       Int32.Parse(report["frob_variable"]) AS frob
    FROM @relation;

另请参见

Aha!这就是我要找的。Json数组提取!