Created
June 12, 2025 07:57
-
-
Save Atom1cByte/3301291a94cb3f6acbe44401c3d51a7c to your computer and use it in GitHub Desktop.
quick someliner to truncate json with jq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jq 'map( | |
| if type == "array" then | |
| "[" + (.[0:5] | map(tostring) | join(", ")) + (if length > 5 then ", ..." else "" end) + "] (array, len=" + (length|tostring) + ")" | |
| elif type == "object" then | |
| "{ " + (to_entries[0:5] | map("\(.key): \(.value|tostring)") | join(", ")) + (if (to_entries | length) > 5 then ", ..." else "" end) + " } (object, keys=" + (keys|length|tostring) + ")" | |
| else | |
| (. | tostring) + " (" + (type) + ")" | |
| end | |
| )' file.json |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
better one: