【发布时间】:2020-07-06 00:06:42
【问题描述】:
我有一个 JSON 实体流。这是其中之一,称为“信息”:
null
null
{
"id": "qwefhu214o",
"number": "2346",
"date": "28.01.2019"
}
null
null
{
"id": "esg324lif",
"number": "1378",
"date": "29.05.2019"
}
{
"id": "gwrs853sdf",
"number": "4487",
"date": "20.12.2019"
}
我想从嵌套的 json 中提取键,所以看起来像这样:
null
null
{
"info_id": "qwefhu214o",
"info_number": "2346",
"info_date": "28.01.2019"
}
null
null
{
"info_id": "esg324lif",
"info_number": "1378",
"info_date": "29.05.2019"
}
{
"info_id": "gwrs853sdf",
"info_number": "4487",
"info_date": "20.12.2019"
}
我尝试了这个,但它不起作用:
jqr::jq('.[].info |= with_entries(.key |= "info_" + .)')
上面写着:
Error: lexical error: invalid char in json text.
NA
(right here) ------^
我猜是因为 NULL。我怎么能这样做?我应该放在某个地方吗?在代码中?该代码适用于存在 np NULL 的情况
【问题讨论】: