JSON datatype GSoC 2010

From PostgreSQL wiki
Jump to navigationJump to search

Overview

JSON [1] is a data interchange format somewhat similar in purpose to XML. Similar to how PostgreSQL has an XML datatype and related functions; this project will add a JSON datatype and functions. Because of structural differences between XML and JSON, the set of functions will need to be different.

Adding JSON support to PostgreSQL will enable users to store and work with JSON content in a similar fashion as they can work with XML today. JSON is not a “moving target” and is lighter than XML, meaning it should be faster and will probably not depend on an external library. If the community decides JSON support should be built-in rather than an external module, JSON may become the preferred medium of storage for structured and EAV-type data in PostgreSQL.

Student name: Joseph Adams Mentor name: Magnus Hagander

Deliverables

Upon completion, there will be JSON support for PostgreSQL (either built-in or as an additional module) along with the necessary documentation and test cases. Casting a string to JSON will perform validation (e.g. `SELECT '[1, '::json` will fail because of the missing end bracket). Users will be able to convert sets to JSON (e.g. SELECT json_object('abc' AS foo, 123 AS bar) ) and from JSON (e.g. SELECT * FROM json_each('{"a":1, "b":2}')). The exact specifics will depend on community input, but will probably be inspired by existing XML and hstore functions.

Project Schedule (to finish)

until May 24:

  • Discuss with the PostgreSQL developer community the naming and semantics of JSON support, primarily set and value conversion functions.
  • Learn about how to write a PostgreSQL module (JSON support will probably become an additional supplied module, though this is up to the community).
  • Create a public repository for my project, most likely on http://git.postgresql.org/ .

May 24 - May 31: PostgreSQL-ify the JSON library. Change malloc to palloc, use encoding functions from pg_wchar.h, inherit the JSON node structure from Node (maybe), etc.

May 31 - June 7: Implement the JSON datatype (no additional functions). This should be semi-trivial, as I can reference type code in src/backend/utils/adt/ .

June 7 - June 14: Freeze. Write documentation and testcases, and make a usable draft release of the json module with this functionality.

June 14 - June 28 (2 weeks): Implement *_to_json functions for converting strings, numbers, and bools to JSON, and json_to_* functions for the opposite conversion.

June 28 - July 5: Implement the function which converts a tuple to a JSON object (similar in purpose to xmlforest [2]).

July 5 - July 12: Freeze. Write documentation and testcases, and make a usable draft release of the json module with this functionality.

July 12 - July 19: Implement a function converting a JSON object to a set of key/value tuples (similar to each in hstore [3]).

July 19 - July 26: Implement a JSON concatenation operator (similar to || in hstore), and an aggregate concatenation function (similar to xmlagg [4]).

July 26 - August 9: to finish

August 9 - August 16: Freeze: Write documentation and testcases, and make a usable draft release of the json module with this functionality. August 16 is the firm 'pencils down' date.