Convert values to strings before using join function for jq 1.5 support #491
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR aim to accomplish?:
Fixes display empty of data from PADD.sh when running on a machine with jq 1.5.
For a while now my RPi 3 hasn't been showing statistics, and I finally dug into it today. By redirecting stdout to a text file, I was able to see some errors being thrown by the script:
The contents of
padd_output.txtwere (colorized and centered, and this output is from a different run than the json included below):Further investigation (running script with
-xand poking around) showed the root cause was thatGetPADDDatawasn't able to parse the json correctly:$ response='{"recent_blocked":"mask-h2.icloud.com","active_clients":29,"gravity_size":96372,"top_domain":"api.ring.com","top_blocked":"mask.icloud.com","top_client":"hass.djackson.org","blocking":"enabled","queries":{"total":64273,"blocked":9554,"percent_blocked":14.864717483520508},"cache":{"size":10000,"inserted":3658,"evicted":0},"system":{"uptime":2342,"memory":{"ram":{"total":945360,"free":176408,"used":177216,"available":697372,"%used":18.745874587458747},"swap":{"total":102396,"free":102396,"used":0,"%used":0}},"procs":152,"cpu":{"nprocs":4,"%cpu":3.875,"load":{"raw":[0.109375,0.1240234375,0.1474609375],"percent":[2.734375,3.1005859375,3.6865234375]}},"ftl":{"%mem":13.131505012512207,"%cpu":0.600000023841858}},"node_name":"pihole","host_model":"Raspberry Pi 3 Model B Plus Rev 1.3","iface":{"v4":{"addr":"10.10.10.2","rx_bytes":{"value":53.815188,"unit":"M"},"tx_bytes":{"value":8.070791,"unit":"M"},"num_addrs":1,"name":"eth0","gw_addr":"10.10.10.1"},"v6":{"addr":"fe80::6efa:d688:3be7:840a","num_addrs":1,"name":"eth0","gw_addr":null}},"version":{"core":{"local":{"branch":"master","version":"v6.3","hash":"5a23c9c3"},"remote":{"version":"v6.3","hash":"5a23c9c3"}},"web":{"local":{"branch":"master","version":"v6.4","hash":"cd0c392d"},"remote":{"version":"v6.4","hash":"cd0c392d"}},"ftl":{"local":{"hash":"8d1add8d","branch":"master","version":"v6.4.1","date":"2025-11-27 18:02:19 +0000"},"remote":{"version":"v6.4.1","hash":"8d1add8d"}},"docker":{"local":null,"remote":null}},"config":{"dhcp_active":true,"dhcp_start":"10.10.11.1","dhcp_end":"10.10.11.254","dhcp_ipv6":false,"dns_domain":"djackson.org","dns_port":53,"dns_num_upstreams":2,"dns_dnssec":false,"dns_revServer_active":true,"privacy_level":0},"%mem":13.133621215820312,"%cpu":0.600000023841858,"pid":21126,"sensors":{"cpu_temp":65.528,"hot_limit":60,"unit":"C"},"took":0.011656045913696289}' $ echo "${response}" | jq -r 'paths(scalars | true) as $p | [$p | join(".")] + [if getpath($p)!=null then getpath($p) else "null" end] | join("=")' recent_blocked=mask-h2.icloud.com jq: error (at <stdin>:1): string ("=") and number (29) cannot be addedUnlike my really old version of jq, both PADD and pi-hole are fully up-to-date:
How does this PR accomplish the above?:
Fixes the issue by converting json keys and values to strings using
tostringbefore callingjoin().The jq 1.6 documentation for
joinadded this text when compared to the docs for v1.5:I haven't done much with jq, so it took some trial and error to get my proposed fix. There might be a more elegant way to do it. Or, maybe you would prefer to require jq >= 1.6, which would be fine.
I've tested the one-liner in a terminal with jq 1.8 on a different machine, and as far as I can tell, my changed version continues to work correctly.
I did not (yet?) change the comment describing the
jqinvocation inGetPADDData, but maybe it should be.By submitting this pull request, I confirm the following:
git rebase)