Assuming the input is fixed and that each object has a "technico" field, you can run the following:
jq -r -c '
select(.contact_type | contains("tecnico"))
| {FirstName: .first_name},{LastName: .last_name},{Email: .email}, ""
'
The -r option suppresses the quotation marks around the top-level string, and the trailing , ""
has the effect of adding a new-line after each object.
If you only want the additional blank lines between the objects, then you might find it easier to use a complementary tool such as sed
or awk
. However, here is a jq-only solution that assumes jq has been called with the -n option in addition to -r -c:
def nl(stream):
foreach stream as $s (-1; .+1; if . > 0 then "" else empty end, $s);
nl(inputs | select(.contact_type | contains("tecnico"))
| if type == "string"
then .
else {FirstName: .first_name},{LastName: .last_name},{Email: .email}
end
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…