Skip to content

Instantly share code, notes, and snippets.

@thn929
thn929 / jq_tricks.sh
Last active November 10, 2022 15:58
jq tricks
#1: human-readable dates and timestamps within context
```bash
cat something.json | jq 'walk(if type == "object" then with_entries(if(.key | contains("date")) or (.key | contains("timestamp")) then {key, value: .value|.[0:10]|tonumber|todate} else . end) else . end)'
```
#2: Like above, but filters down to just the dates and timestamps, and displays the paths to each field
```bash
cat something.json | jq 'walk(if type == "object" then with_entries(if(.key | contains("date")) or (.key | contains("timestamp")) then {key, value: .value|.[0:10]|tonumber|todate} else . end) else . end)' | jq 'del(.. | .source_data?)' | jq -r 'paths(scalars) as $p | [ ( [ $p[] | tostring ] | join(".") ), ( getpath($p) | tojson )] | join(": ")' | grep 'date\|time'
```
@thn929
thn929 / server.properties
Created October 10, 2017 23:29
Kafka server props
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software