0

I am trying to parse a JSON object into an APEX select list. There are ways to parse a JSON object, but I have not yet come across or figured a way to parse a JSON object and use it as a select list in the Apex application. Most questions have been around generating JSON from the Apex data. Any help would be appreciated. Thanks!

The data I want to parse (simpler example) is as below:

    {
  "verumModelObjectName": "Address",
  "verumObjectList": [
    {
      "locationID": "20005",
      "country": "ARE"
    },
    {
      "locationID": "31083",
      "country": "ARE"
    },
    {
      "locationID": "31118",
      "country": "ARE"
    },
    {
      "locationID": "32185",
      "country": "ARE"
    },
    {
      "locationID": "32138",
      "country": "ARE"
    },
    {
      "locationID": "32070",
      "country": "ARE"
    },
    {
      "locationID": "32094",
      "country": "ARE"
    },
    {
      "locationID": "20006",
      "country": "ARG"
    },
    {
      "locationID": "32196",
      "country": "ARG"
    },
    {
      "locationID": "41057",
      "country": "ARG"
    },
    {
      "locationID": "31032",
      "country": "ARG"
    },
    {
      "locationID": "33212",
      "country": "ARG"
    },
    {
      "locationID": "3558",
      "country": "ARG"
    },
    {
      "locationID": "33126",
      "country": "ARG"
    },
    {
      "locationID": "31007",
      "country": "ARG"
    },
    {
      "locationID": "33127",
      "country": "ARG"
    },
    {
      "locationID": "31100",
      "country": "ASM"
    },
    {
      "locationID": "20008",
      "country": "AUS"
    },
    {
      "locationID": "20591",
      "country": "AUS"
    },
    {
      "locationID": "31125",
      "country": "AUS"
    }]
  "statusCode": 200
}
4
  • Could you post your object definition and what should be on the select list? Commented Sep 16, 2015 at 9:59
  • So, you would like to show the country and return the locationID in the Select list? Commented Sep 18, 2015 at 10:37
  • Hi, I would only like to show the Country in the select list. Thanks! Commented Sep 21, 2015 at 2:08
  • So in this case it should be "ARE,ARG,ASM,AUS"? Commented Sep 21, 2015 at 11:03

1 Answer 1

0

did you check apex_json package in 5.0 https://docs.oracle.com/cd/E59726_01/doc.50/e39149/apex_json.htm#AEAPI29640

you can parse your data by using this package and then for select list you should create a dynamic select list with d display and r return values as below. it should work

 select col1 d, col2 r
from xmltable (
        '/json/verumObjectList/row'
        passing apex_json.to_xmltype('

    {
  "verumModelObjectName": "Address",
  "verumObjectList": [
    {
      "locationID": "20005",
      "country": "ARE"
    },
    {
      "locationID": "31083",
      "country": "ARE"
    },
    {
      "locationID": "31118",
      "country": "ARE"
    },
    {
      "locationID": "32185",
      "country": "ARE"
    },
    {
      "locationID": "32138",
      "country": "ARE"
    },
    {
      "locationID": "32070",
      "country": "ARE"
    },
    {
      "locationID": "32094",
      "country": "ARE"
    },
    {
      "locationID": "20006",
      "country": "ARG"
    },
    {
      "locationID": "32196",
      "country": "ARG"
    },
    {
      "locationID": "41057",
      "country": "ARG"
    },
    {
      "locationID": "31032",
      "country": "ARG"
    },
    {
      "locationID": "33212",
      "country": "ARG"
    },
    {
      "locationID": "3558",
      "country": "ARG"
    },
    {
      "locationID": "33126",
      "country": "ARG"
    },
    {
      "locationID": "31007",
      "country": "ARG"
    },
    {
      "locationID": "33127",
      "country": "ARG"
    },
    {
      "locationID": "31100",
      "country": "ASM"
    },
    {
      "locationID": "20008",
      "country": "AUS"
    },
    {
      "locationID": "20591",
      "country": "AUS"
    },
    {
      "locationID": "31125",
      "country": "AUS"
    }],
  "statusCode": 200
}


')
        columns
           col1 number path '/row/locationID',
           col2 varchar2(5) path '/row/country' );
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, thanks for the idea. The portal is down currently, so I'll try it out as soon as I can use the API! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.