Re: list elements of set
Slavko <[email protected]> Sat, 27 Sep 2025 17:24:52 +0000
| Newsgroups | gmane.comp.security.firewalls.netfilter.general |
|---|---|
| Message-ID | <[email protected]> |
Dňa 27. septembra 2025 10:59:54 UTC používateľ Kerin Millar <[email protected]> napísal: >You could parse JSON with the popular jq utility, or some other JSON parser of your choosing. Yes, one can parse JSON with jq, but it is not simple task for shell, as output of list sets is, hmm, i don't know how to describe it: 1. the nftables is list of objects, thus one must first filter the "metadata" object, it is first list item, but who know if it is guaranted 2. then one must distinguish, is set object has elem key (empty sets miss it 3. then one must determine elem key's type, as it can be list of values (scalar) or list of objects 4. then one must decide if value of elem object is in elem or prefix key 5. then one must again distinguish, if value of elem.elem key is scalar or object 6. and finally decide key(s) of that object to get real value (val, prefix, concat) Thus yes, it is valid JSON, which is parseable by standard JSON's tools, but with jq one need either to construct horrible script, or create set of simple sctpts on per set base... I currently play with it in python, and with my real set of sets, i am still on step 5 (of above). Please, why is JSON output as non user friendly and differs by set's settings? regards -- Slavko https://www.slavino.sk/