Thanks, Birgitta. Now it makes sense despite trying changing the commands. Right now, that's were doing adding an identifier at the start. But its concat made it so much better

Thanks a lot!,
Lynelle

message: 5
date: Thu, 2 Aug 2018 17:19:36 +0200
from: "Birgitta Hauser" <Hauser@xxxxxxxxxxxxxxx>
subject: RE: Using JSON_TABLE on an array that starts with a square
bracket

Currently you cannot directly consume json data that starts with an array.
It is not supported by JSON_TABLE
What you can do, is to embedd your array in an object and parse the result.

Something like this:
Select *
from JSON_TABLE('{ "root": ' concat

systools.HTTPGETCLOB('https://urldefense.proofpoint.com/v2/url?u=https-3A__pkgstore.datahub.io_core_country-2Dlist_latest_d&d=DwICAg&c=eIGjsITfXP_y-DLLX0uEHXJvU8nOHrUK8IrwNKOtkVU&r=mESuyOnMNoX2u7kbuvHk4LLfMPdTt1eTsC4o_ZpSoH5zg4geXTWcGqE0CBG3j-x3&m=6evrPHwbbNb0ph4I1oYCulOo5nKtydSoJxj34WFgpPE&s=9RJ6A0LY-UKAkfAtnUWqCEL6cFElNYD8xmUrOZbVong&e=
ata/json/data.json' , '')
concat '}',
'$.root[*]'
Columns( "Code" VarChar(5),
"Name" VarChar(50))) x;

This web service returns:
[{"Code": "AF", "Name": "Afghanistan"},{"Code": "AX", "Name": "\u00c5land Islands"}, ....]

Mit freundlichen Gr??en / Best regards

Birgitta Hauser

"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok) "What is worse than training your staff and losing them? Not training them and keeping them!"
?Train people well enough so they can leave, treat them well enough so they don't want to.? (Richard Branson)


-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxx> On Behalf Of Mendoza, Lynelle I. M.
Sent: Donnerstag, 2. August 2018 14:01
To: rpg400-l@xxxxxxxxxxxx
Subject: Using JSON_TABLE on an array that starts with a square bracket

Hello All,

I was able to get the name and country of JSON array below if it starts with a curly bracket:
{"items":[{"name": "MyFirstCompany","country": "DE"},{"id": 2,"name":
"MySecondCompany", "country": "DE"}]}

using this SQL command:
with y as (
Select * from JSON_TABLE(get_clob_from_file('/test.json'), '$'
columns( nested '$.items[*]' columns(
"name" varchar(30),
"country" varchar(02)
) ) ) x ) select * from y with ur;

However, the JSON data I want to parse starts with a square bracket and looks like this:
'[{"name": "MyFirstCompany","country": "DE"},{"id": 2,"name":
"MySecondCompany", "country": "DE"}]'

But I wasn't able to get any rows using this command:
with y as (
Select * from JSON_TABLE(
'[{"name": "MyFirstCompany","country": "DE"},{"id": 2,"name":
"MySecondCompany", "country": "DE"}]', '$'
columns(
nested 'lax $[*]' columns(
"name" varchar(30),
"country" varchar(02)
) ) ) x
) select * from y with ur;

Kindly advise on correct command on parsing JSON array that starts with a square bracket.

Thanks,
Lynelle


________________________________

This message is for the designated recipient only and may contain privileged, proprietary, or otherwise confidential information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the e-mail by you is prohibited. Where allowed by local law, electronic communications with Accenture and its affiliates, including e-mail and instant messaging (including content), may be scanned by our systems for the purposes of information security and assessment of internal compliance with Accenture policy. Your privacy is important to us.
Accenture uses your personal data only in compliance with data protection laws. For further information on how Accenture processes your personal data, please see our privacy statement at https://www.accenture.com/us-en/privacy-policy.
____________________________________________________________________________
__________

www.accenture.com
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.midrange.com_mailman_listinfo_rpg400-2Dl&d=DwICAg&c=eIGjsITfXP_y-DLLX0uEHXJvU8nOHrUK8IrwNKOtkVU&r=mESuyOnMNoX2u7kbuvHk4LLfMPdTt1eTsC4o_ZpSoH5zg4geXTWcGqE0CBG3j-x3&m=6evrPHwbbNb0ph4I1oYCulOo5nKtydSoJxj34WFgpPE&s=jGHziNsd2Hj3HbOVlVSmgACBIVSvjWiWL9FuL5UV4so&e=
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at https://urldefense.proofpoint.com/v2/url?u=https-3A__archive.midrange.com_rpg400-2Dl&d=DwICAg&c=eIGjsITfXP_y-DLLX0uEHXJvU8nOHrUK8IrwNKOtkVU&r=mESuyOnMNoX2u7kbuvHk4LLfMPdTt1eTsC4o_ZpSoH5zg4geXTWcGqE0CBG3j-x3&m=6evrPHwbbNb0ph4I1oYCulOo5nKtydSoJxj34WFgpPE&s=EZHeCObrgAmB1pGlkKxH9YL0sQK1yq6QVbDOshn3sjE&e=.

Please contact support@xxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate link:
https://urldefense.proofpoint.com/v2/url?u=http-3A__amzn.to_2dEadiD&d=DwICAg&c=eIGjsITfXP_y-DLLX0uEHXJvU8nOHrUK8IrwNKOtkVU&r=mESuyOnMNoX2u7kbuvHk4LLfMPdTt1eTsC4o_ZpSoH5zg4geXTWcGqE0CBG3j-x3&m=6evrPHwbbNb0ph4I1oYCulOo5nKtydSoJxj34WFgpPE&s=85eXEqSFLewmprwy5CDUzVlCaxtCT1V6928kSiTiqPU&e=



------------------------------

Subject: Digest Footer

--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) digest list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.midrange.com_mailman_listinfo_rpg400-2Dl&d=DwICAg&c=eIGjsITfXP_y-DLLX0uEHXJvU8nOHrUK8IrwNKOtkVU&r=mESuyOnMNoX2u7kbuvHk4LLfMPdTt1eTsC4o_ZpSoH5zg4geXTWcGqE0CBG3j-x3&m=6evrPHwbbNb0ph4I1oYCulOo5nKtydSoJxj34WFgpPE&s=jGHziNsd2Hj3HbOVlVSmgACBIVSvjWiWL9FuL5UV4so&e=
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at https://urldefense.proofpoint.com/v2/url?u=http-3A__archive.midrange.com_rpg400-2Dl&d=DwICAg&c=eIGjsITfXP_y-DLLX0uEHXJvU8nOHrUK8IrwNKOtkVU&r=mESuyOnMNoX2u7kbuvHk4LLfMPdTt1eTsC4o_ZpSoH5zg4geXTWcGqE0CBG3j-x3&m=6evrPHwbbNb0ph4I1oYCulOo5nKtydSoJxj34WFgpPE&s=7b1k9dx6DvqAezeczlDc4lzRm5B-AMjJT2uqGbOsSSk&e=.

Please contact support@xxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate link: https://urldefense.proofpoint.com/v2/url?u=http-3A__amzn.to_2dEadiD&d=DwICAg&c=eIGjsITfXP_y-DLLX0uEHXJvU8nOHrUK8IrwNKOtkVU&r=mESuyOnMNoX2u7kbuvHk4LLfMPdTt1eTsC4o_ZpSoH5zg4geXTWcGqE0CBG3j-x3&m=6evrPHwbbNb0ph4I1oYCulOo5nKtydSoJxj34WFgpPE&s=85eXEqSFLewmprwy5CDUzVlCaxtCT1V6928kSiTiqPU&e=

------------------------------

End of RPG400-L Digest, Vol 17, Issue 368
*****************************************

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].