Load an Array of JSON Documents into a Collection
To load
data from collections in the Cloud, you first store your object storage credentials in your Autonomous Database and then use PL/SQL procedure DBMS_CLOUD.COPY_COLLECTION
to load documents into a
collection. This topic explains how to load documents to your database from a JSON array in a
file.
You can also load documents from a JSON array in a file into a collection using SODA for REST. See Load Purchase-Order Sample Data Using SODA for REST.
This example uses the JSON file fruit_array.json
. The
following shows the contents of the file fruit_array.json
:
[{"name" : "apple", "count": 20 },
{"name" : "orange", "count": 42 },
{"name" : "pear", "count": 10 }]
Before loading data into Autonomous Database, copy the data to your object store as follows:
-
Create a bucket in the object store. For example, create an Oracle Cloud Infrastructure Object Store bucket from the Oracle Cloud Infrastructure Object Storage link, in your selected Compartment, by clicking Create Bucket, or use a command line tool such as the following OCI CLI command:
oci os bucket create -name json_bucket -c <compartment id>
-
Copy the JSON file to the object store. For example, the following OCI CLI command copies the JSON file
fruit_array.json
to the object store:oci os object put --bucket-name json_bucket --file "fruit_array.json"
Load the JSON file from object store into a SODA collection named
fruit2
on your database:
The load of fruit_array.json
, with DBMS_CLOUD.COPY_COLLECTION
using the format
option unpackarrays
recognizes array values in the source and instead of
loading the data as a single document, as it would by default, the data is loaded in the
collection fruit2
with each value in the array as a single document.
Parent topic: Load JSON on Autonomous Database