Convert between binary and json