Available in versions: Dev (3.22) | Latest (3.21) | 3.20 | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12

Reading JSON

Supported by ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

DSLContext.fetchFromJSON() is the inverse operation of exporting JSON. It parses a JSON string in the format produced by Result.formatJSON() into a Result<Record>:

Result<Record> result = create.fetchFromJSON(
    "{\"fields\":[{\"name\":\"ID\",\"type\":\"INTEGER\"},"
  + "            {\"name\":\"AUTHOR_ID\",\"type\":\"INTEGER\"},"
  + "            {\"name\":\"TITLE\",\"type\":\"VARCHAR\"}],"
  + " \"records\":[[1,1,\"1984\"],"
  + "            [2,1,\"Animal Farm\"]]}"
);

Records may be encoded as arrays (the default) or as objects (see org.jooq.JSONFormat.RecordFormat).

If the "fields" header contains "type" information, it is used to produce fields of the corresponding data types. Otherwise, fields are of type String. See the section about working with in-memory results to learn how to convert such results to other types.

If the goal is to load JSON data directly into a database table, the Loader API's JSON support may be a better fit.

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo