I've just started using Postgres 9.5 and looking forward to using the JSON functionality it now includes.

Just wondering how other users of Phalcon are going about automatically converting their arrays/objects back and forth with json_encode() and json_decode() when your models are saved/loaded?

My initial thoughts are to add the following line to the model's beforeSave() method:

$this->myJsonField = json_encode($this->myJsonField);

and the following line to the model's afterFetch() method:

$this->myJsonField = json_decode($this->myJsonField);

But maybe there's some other ways to do it that have some advantages?

Could it be a bad idea to be overwriting the same class property? Alternatively I could have another property to distingush the regular object/array version and the JSON encoded string? i.e. $this->myJsonField for the encoded string, and $this->myJsonFieldArray for the decoded version?

Also interested in hearing whether most of you typically json_decode() to objects -or- arrays when there's no important case specific reason to prefer one over the other? What do you prefer to work with normally?

Keen for any feedback on this or anything related at all. </textarea> Thanks.