English 中文(简体)
如何使q子产生一个长期的数据集?
原标题:How to get jq to output a long dataset?

附录一

{"id": "one", "colors": [{"color": "blue"}, {"color": "red"}]}
{"id": "two", "colors": [{"color": "green"}]}

我怎样把产出摆在下面?

one blue
one red
two green

这是一次失败的尝试:

$ cat tmp/test.json  | jq -r  .id, .colors[].color 
one
blue
red
two
green

这是第二次失败尝试:

$ cat tmp/test.json  | jq -r  [.id, .colors[].color]|@tsv 
one blue    red
two green
问题回答

最直接的方法:

jq -r  .id + " " + .colors[].color  my.ndjson

由于你提到<代码>@tsv,并且由于@tsv输出具有各种潜在优势,你也不妨考虑:

.id as $id | .colors[] | [$id, .color] | @tsv

或者,如果你不想使用<条码>作为,则:

[[limit(.colors|length; repeat(.id))], [.colors[].color]] | transpose[] | @tsv

<代码>combinations功能输出所有投入要素组合。 每一条<条码>id,<条码>。

$ jq -cr  [[.id], [.colors[].color]] | combinations  test.json
["one","blue"]
["one","red"]
["two","green"]

$ jq -r  [[.id], [.colors[].color]] | combinations | join(" ")  test.json
one blue
one red
two green

这里还有一个版本,但不得不把几条 j子连接起来,使之也能够发挥作用,而只是把这些部分从中排入新的初生物质,然后把这些物品 par平起来,并与之相仿的“John Kugleman”在座(可能不是说谎:D)。

http://www.id.id,“color”: .colors[].color} jq - [.[] join(”)

产出如:

one blue
one red
two green




相关问题
JQuery/MVC Search Issue

I have inherited a piece of work where the entry screen shows a summary of 20 calculated variables. E.g. Var A (250), Var B (79). Clicking on any of these links takes the user to a view with a ...

jQuery quicksearch plug-in tinkering with JSON

I ve implemented the quicksearch plugin by Rik Lomas and I love it for an application in a custom CMS I m building. I was wondering though, since I m going to have a bizillion items in the table if ...

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

PHP json_decode question

i m trying to use json_decode to combine a few json objects and then re-encode it. my json looks like: { "core": { "segment": [ { "id": 7, "...

Converting JSON data to Java object

I want to be able to access properties from a JSON string within my Java action method. The string is available by simply saying myJsonString = object.getJson(). Below is an example of what the string ...

热门标签