Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 580

Select one of several subattributes dependent on its content

$
0
0

I have a JSON Output describing the configuration of an OPNSense Firewall.

I want to condense the output into something more useful. Consider the following element of a list of VLANs

[  {"key": "0eb660b0-555a-469e-be04-8c3584108f9b","value": {"if": {"igb1": {"value": "igb1 (64:62:66:22:6e:d0) [UNTAGGED]","selected": 0        },"igb2": {"value": "igb2 (64:62:66:22:6e:d1) [tagged]","selected": 1        }      },"tag": "20","pcp": {"1": {"value": "Background (1, lowest)","selected": 0        },"0": {"value": "Best Effort (0, default)","selected": 1        },"2": {"value": "Excellent Effort (2)","selected": 0        }      },"proto": {"": {"value": "Auto","selected": 1        },"802.1q": {"value": "802.1Q","selected": 0        },"802.1ad": {"value": "802.1ad","selected": 0        }      },"descr": "USERS: PCs und Handies  ","vlanif": "vlan0.20"    }  }]

I would like to see only the content for if, pcp or proto, which have selected ==1. Whether I get their key or their value is anther problem. The result could look like this:

[  {"key": "0eb660b0-555a-469e-be04-8c3584108f9b","value": {"if": {"igb2": {"value": "igb2 (64:62:66:22:6e:d1) [tagged]","selected": 1        }      },"tag": "20","pcp": {"0": {"value": "Best Effort (0, default)","selected": 1        }      },"proto": {"": {"value": "Auto","selected": 1        }      },"descr": "USERS: PCs und Handies  ","vlanif": "vlan0.20"    }  }]

See online

I tried all variants of select which occured to me. But i don't know how to select a subattribute and not the whole object.


Viewing all articles
Browse latest Browse all 580

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>