json generation enhancements

Andrew Dunstan <andrew@dunslane.net>

From: Andrew Dunstan <andrew@dunslane.net>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2013-01-11T16:00:20Z
Lists: pgsql-hackers
I have not had anyone follow up on this, so I have added docs and will 
add this to the commitfest.

Recap:

This adds the following:

     json_agg(anyrecord) -> json
     to_json(any) -> json
     hstore_to_json(hstore) -> json (also used as a cast)
     hstore_to_json_loose(hstore) -> json

Also, in json generation, if any non-builtin type has a cast to json, 
that function is used instead of the type's output function.

cheers

andrew