Tips for extracting a JSON object stored in an array using Oracle APEX v5.1

Here is a sample JSON Object array that I am working with:

[
{
"type": "Campaign",
"currentStatus": "Active",
"id": "206",
"depth": "complete",
"folderId": "1428",
"name": "Car Loan",
"isReadOnly": "false"
},
{
"type": "Debate",
"currentStatus": "Active",
"id": "207",
"depth": "pending",
"folderId": "1429",
"name": "House Loan",
"isReadOnly": "true"
}
]

I am trying to figure out how to iterate through each JSON object within this array.

My goal is to generate a report displaying all the columns for each of these two JSON object records.

I have explored using apex_json.get_count, but I am unsure of how to implement it in this scenario.

Answer №1

If your database version is Oracle 12c, you can utilize json_table as shown below: (Keep in mind that a parent tag is required. In this example, "row" is used)

SELECT jsn.*
  FROM   JSON_TABLE('{"row":[{"type": "Campaign","currentStatus": "Active","id": "206","depth": "complete","folderId": "1428","name": "Car Loan","isReadOnly": "false"},{"type": "Debate","currentStatus": "Active","id": "207","depth": "pending","folderId": "1429","name": "House Loan","isReadOnly": "true"}] }'
             , '$.row[*]'
     COLUMNS (type          VARCHAR2(50 CHAR) PATH '$.type',
              currentStatus VARCHAR2(50 CHAR) PATH '$.currentStatus',
              id            VARCHAR2(50 CHAR) PATH '$.id',
              depth         VARCHAR2(50 CHAR) PATH '$.depth',
              folderId      VARCHAR2(50 CHAR) PATH '$.folderId',
              name          VARCHAR2(50 CHAR) PATH '$.name',
              isReadOnly    VARCHAR2(50 CHAR) PATH '$.isReadOnly')) jsn; 

If your database version is not Oracle 12c, you can opt for apex_json. You can use a pipeline function for reporting purposes like:

-- Define the necessary types to support the table function.
DROP TYPE t_tf_tab;
DROP TYPE t_tf_row;

CREATE TYPE t_tf_row AS OBJECT (
  type          varchar2(50),
  currentStatus varchar2(50),
  id            varchar2(50),
  depth         varchar2(50),
  folderId      varchar2(50),
  name          varchar2(50),
  isReadOnly    varchar2(50)
);
/

CREATE TYPE t_tf_tab IS TABLE OF t_tf_row;
/

-- Create the table function.
CREATE OR REPLACE FUNCTION get_tab_tf RETURN t_tf_tab AS
  l_tab  t_tf_tab := t_tf_tab();
  l_json CLOB := '{"row": [ {
                                "type": "Campaign",
                                "currentStatus": "Active",
                                "id": "206",
                                "depth": "complete",
                                "folderId": "1428",
                                "name": "Car Loan",
                                "isReadOnly": "false"
                                },
                                {
                                "type": "Debate",
                                "currentStatus": "Active",
                                "id": "207",
                                "depth": "pending",
                                "folderId": "1429",
                                "name": "House Loan",
                                "isReadOnly": "true"
                                }
                                ] }';

     j apex_json.t_values;
     l_path  VARCHAR2(100);

    BEGIN
      apex_json.parse(l_json);

      FOR i IN 1..apex_json.get_count(p_path   => 'row')
      LOOP
        l_tab.extend;
        l_tab(l_tab.last) := t_tf_row( apex_json.get_varchar2( p_path => 'row[%d].type', p0 => i),
                                       apex_json.get_varchar2( p_path => 'row[%d].currentStatus', p0 => i),
                                       apex_json.get_varchar2( p_path => 'row[%d].id', p0 => i),
                                       apex_json.get_varchar2( p_path => 'row[%d].depth', p0 => i),
                                       apex_json.get_varchar2( p_path => 'row[%d].folderId', p0 => i),
                                       apex_json.get_varchar2( p_path => 'row[%d].name', p0 => i),
                                       apex_json.get_varchar2( p_path => 'row[%d].isReadOnly', p0 => i)
                                     );
      END LOOP;

  RETURN l_tab;
END;
/

-- Test the table function.
SELECT *
FROM   TABLE(get_tab_tf)
ORDER BY id DESC;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Capture the selected hyperlink and show the corresponding page title in a designated box for reference

I want to track the links that users click on and display them in a box with an image and name of the page. Additionally, I would like to show how long the user spent on each page below the image. The images in the box should also be clickable links to the ...

The AngularJS $HTTP loop counter fails to update

When working with an HTTP service and binding JSON data to HTML, I implemented the following code: This function uses a 2-second timer to automatically fetch data whenever there is a change in the backend. function sampleDevices ...

Resize a group of images to match the parent's width and height dimensions

I am working with a div that contains variously-sized images and is nested inside a parent container. <div id="parentContainer"> <div id="boxToScale"> <img src="http://placehold.it/350x150" /> <img src="http://placehold.it/150 ...

Encountered a NodeJS error while attempting to locate information in a mongo DB: UnhandledPromiseRejectionWarning

In my MEAN stack application, I am working on implementing a login feature that includes social login functionality. When a new user attempts to log in using Facebook, I need to verify if their Facebook account is already registered in my MongoDB database. ...

What could be causing the removal of style classes from my element after it is appended?

Could you please explain how it functions? I am attempting to append a div with content using innerHTML and it is working, but without any of the styling classes being applied. const element = document.createElement("div"); element.classList.add("col ...

Sharing specific calls from an established asp.net-mvc website with external REST clients on an internal network?

I currently have a functioning asp.net-mvc website and now I am seeking to make some of my internal calls available to external applications that are exclusively used within the site. This is all happening in an intranet setting within my organization. Af ...

Performing an AJAX request to the database when a change occurs, prior to submitting the

In my user setup/create form, I am including a field for the users' license/certification number which needs to be validated and returned to a specific DIV Onchange before the form is submitted. I have heard that using AJAX POST is the way to achieve ...

Setting up node.js for angular - serving static files with connect.static and running unit tests

Currently, I am in the process of setting up a basic node webserver by following a tutorial outlined in Pro AngularJS published by Apress. Node.js along with both the connect and karma modules have been successfully installed on my system. During the ins ...

Exploring the use of the escape character "" in XSL with JSON parsing

I need assistance with accurately parsing the phrase \"SOME TEXT\" in an XSL file. Here is my inquiry { "MessageRequest": { "Header": { "HeaderRequest": { "consumer": "TCRM", "country": "COUNTRY", "dispositiv ...

Using touch-action to enable movement from the last item to the first item in HTML/C

Currently, I am utilizing the touch-action property in my carousel which auto slides without any issues. However, I am facing a problem where when I scroll using touch-action, it stops at the last slide instead of looping back to the first slide. My goal i ...

Issues with Angular updating the *ngFor Loop

I'm looking to showcase a lineup of upcoming concerts in my HTML, sourced from a web API (which is functioning correctly). The API is encapsulated within a ConcertService: @Injectable({ providedIn: 'root' }) export class ConcertService { ...

I'm curious if the response order will mirror the URL order in my situation

QUERY: Upon reviewing the following link: Promise.all: Order of resolved values I am doubtful about its relevance to my specific scenario. Can I always expect responses to be in the same order as urls? EXAMPLE: var urls = []; for (var i = 0; i < d ...

Assess the HTML containing v-html injection

Is there a way to inject raw HTML using Vue, especially when the HTML contains Vue markup that needs to be evaluated? Consider the following example where HTML is rendered from a variable: <p v-html="markup"></p> { computed: { m ...

ObjectMapper is unable to deserialize an instance of java.lang.Double

I'm trying to extract data from a string sent by Node.js using the following code: User[] users = mapper.readValue(resultPayload, User[].class); This is my User class: public class User { private double latitude; private double longitude; ...

Using Three.js to create a distorted texture video effect

Check out the example linked here for reference: In this particular project, there are two cylinders involved - an outer cylinder with an image texture and an inner cylinder with a video texture. Once the second cylinder is created and added to the scene, ...

Despite receiving a 200OK response, the API in GetStaticProps() is not providing any data

I'm trying to send an axios.get request to an API within getStaticProps() in next.js. Although the response is coming back with a 200OK status, I can't seem to locate the data in the response. Where should I be looking for this data? The data ...

Error: The JavaScript in Bootstrap requires jQuery version 1.9.1 or newer. Please make sure you are using the correct version

I've been attempting to access using Java code and the latest release of HTMLUnit (version 2.37.0, which I sourced from a jar download website along with all its dependencies). final WebClient webClient = new WebClient(); webClient.getOptions().setT ...

What is the best way to retain the leading zeros when creating a new Number() in JavaScript?

Hey everyone, I'm running into some issues with this specific function. const incrementString = str => { if (!str.match(/[\d+]$/)){ return str += 1 } else{ return str.replace(/[\d+]$/, match => new Number(match) + 1) } ...

Generating text upon clicking by utilizing vue apex charts dataPointIndex

Is there a way to populate a text area on click from an Apex chart? The code pen provided below demonstrates clicking on the bar and generating an alert with the value from the chart. Instead of displaying this value in an alert, I am looking to place it o ...

Using Conditionals in Unstated (React)

Currently, I am in the process of incorporating Unstated into my react application. To practice using Unstated, I developed a basic app that displays a Note. Below is my implementation for the NoteContainer: class NoteContainer extends Container { s ...