libpg_query icon indicating copy to clipboard operation
libpg_query copied to clipboard

JSON format documentation

Open inad9300 opened this issue 7 years ago • 1 comments

Is there any place which summarizes the shape of the JSON returned by the parser? It seems something crucial to me, but it's proving very hard to find.

I'm working with pg-query-parser in TypeScript, and I would like to create type definitions for the result of the parse function to be able to work with the library safely.

inad9300 avatar Nov 17 '18 11:11 inad9300

@inad9300 Good question - there is no documentation per se, but there are JSON files that contain definitions, so you should be able to auto-generate things from there.

The files to look at are https://github.com/lfittl/libpg_query/blob/10-latest/srcdata/nodetypes.json and https://github.com/lfittl/libpg_query/blob/10-latest/srcdata/struct_defs.json (and others in that directory).

You can also look at https://github.com/lfittl/libpg_query/blob/10-latest/scripts/generate_json_outfuncs.rb for an example how those files are used (to generate the code that outputs the JSON from the internal structs)

lfittl avatar Nov 17 '18 23:11 lfittl