I’ve been playing around with some more of the new JSON features in Oracle Database 12c Release 2 (12.2).
The first thing I tried was the new PL/SQL support for the JSON functions and conditions that were introduced for SQL in 12.1. That was all pretty obvious.
Next I moved on to the new PL/SQL objects for JSON. These are essentially a replacement for APEX_JSON as far as generation and parsing of JSON data are concerned. If I’m honest I was kind-of confused by this stuff at first for a couple of reasons.
If you are coming to it with an APEX_JSON mindset it’s easy to miss the point. Once you “empty your cup” it’s pretty straight forward.
The documentation is pretty terrible at the moment. There are lots of mistakes. I tweeted about this the other day and some folks from the Oracle documentation team got back to me about it. I gave them some examples of the problems, so hopefully it will get cleaned up soon!
I was originally intending to write a single article covering both these JSON new features, but it got clumsy, so I separated them.
The second one isn’t much more than a glorified links page at the moment, but as I cover the remaining functionality it will either expand or contain more links depending on the nature of the new material. Big stuff will go in a separate article. Small stuff will be included in this one.
I also added a new section to this recent ORDS article, giving an example of handling the JSON payload using the new object types.
We publish a number of XML web services from the database using the PL/SQL web toolkit, as described here. In more recent times we’ve had a number of requirements for JSON web services, so we did what most people probably do and Googled for “json pl/sql” and got a link to PL/JSON.
I know about the support for JSON in 12c, but we are not on 12c for these projects and that’s more about consuming JSON, rather than publishing it.
People seemed reasonably happy with PL/JSON, so I thought no more about it. At the weekend, kind-of by accident, I came across the APEX_JSON package that comes as part of APEX 5 and thought, how could I have missed that?
This is not a slight against PL/JSON, but given the choice of using something built and supported by Oracle, that is already in the database (we have APEX 5 in most databases already) or loading something else, I tend to pick the Oracle method. Since then I’ve been having a play with APEX_JSON and I quite like it. Here’s what I wrote while I was playing with it.
If you have done anything with XML in PL/SQL, you should find it pretty simple.
I’m guessing this post will result in a few people saying, “What about ORDS?” Yes I know. Because of history we are still mostly using mod_plsql and OHS, but ORDS is on the horizon. Even so, we will probably continue to use APEX_JSON to do the donkey-work, and just use ORDS to front it.