JQ to CSV issues JQ to CSV issues json json

JQ to CSV issues


A simple solution can be obtained using the same technique shown in one of the answers to the similar question you already asked. The only difference is fulfilling your requirements in the case where the "Repairs" key does not exist:

["Name", "Car", "Location", "Repairs:RepairLocation"],(.[] | [.Name]    + (.Car|..|scalars|[.])    + (.Location|..|scalars|[.])    + (.Repairs|..|scalars       | [if . == null then . else "RepairsCompleted:\(.)" end]) )| @csv

Avoiding the repetition with a helper function

def s: .. | scalars | [.];
["Name", "Car", "Location", "Repairs:RepairLocation"],(.[] | [.Name]     + (.Car|s)    + (.Location|s)     + (.Repairs|s|map(if . == null then . else "RepairsCompleted:\(.)" end)))| @csv