Json Encoding of database