danielc
danielc

Reputation: 549

Using JOOQ formatJSON to get column:value pairs

I'd like my formatJSON() result to be column:value pairs.

[{"ID":1,"AUTHOR_ID":1,"TITLE":"1984"},{"ID":2,"AUTHOR_ID":1,"TITLE":"Animal Farm"}]

This blog post (https://blog.jooq.org/2018/01/) suggests the result is possible by setting a formatting option flag somewhere, but I am unable to find how to specify that option. I am just getting the default (?) output:

{"fields":[{"schema":"sss","table":"ttt","name":"ccc1","type":"zzz"},{"schema":"sss","table":"ttt","name":"ccc2","type":"zzz"}],"records":[[1,"x"]]}

I am using jOOQ 3.7.0, but can upgrade if needed.

Upvotes: 4

Views: 1071

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 221305

I am using jOOQ 3.7.0, but can upgrade if needed.

There's your answer. Upgrade to 3.9 or more to profit from #5372. You can then call Formattable.formatJSON(JSONFormat) like this:

String json = result.formatJSON(new JSONFormat()
    .header(false)
    .recordFormat(RecordFormat.OBJECT));

Upvotes: 9

Related Questions