Prepare JSON passing & get all device ids

It's easier to read in Java for now, I'll probably reformat-rename everything later.