Skip to content

Instantly share code, notes, and snippets.

@stopdropandrew
Created November 19, 2019 00:52
Show Gist options
  • Save stopdropandrew/6ee9e8147d5961604a2fca80d99ef076 to your computer and use it in GitHub Desktop.
Save stopdropandrew/6ee9e8147d5961604a2fca80d99ef076 to your computer and use it in GitHub Desktop.
convert adb content query output to json
#!/usr/bin/env ruby
require 'json'
results = `adb shell content query #{ARGV.join(' ')}`
lines = results.split("\n")
rows = lines.map do |line|
match = line.match(/Row: \d+ (.*)/)
next unless match
args = match[1].split(", ").map{|a| a.split("=")}.map {|arg| [arg.first, arg.last == "NULL" ? nil : arg.last]}.to_h
end.compact
puts rows.to_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment