35.22 SDO_UTIL.FROM_JSON
Format
SDO_UTIL.FROM_JSON( geometry IN JSON, crs IN VARCHAR2 DEFAULT NULL, srid IN VARCHAR2 DEFAULT -1 ) RETURN SDO_GEOMETRY;
or
SDO_UTIL.FROM_JSON( geometry IN CLOB, crs IN VARCHAR2 DEFAULT NULL, srid IN VARCHAR2 DEFAULT -1 ) RETURN SDO_GEOMETRY;
Description
Converts a JSON object (or more specifically a geometry object in JSON format) to a Spatial geometry object.
Parameters
Usage Notes
Note:
The SDO_UTIL.FROM_JSON function is supported only if Oracle JVM is enabled on your Oracle Autonomous Database Serverless deployments. To enable Oracle JVM, see Use Oracle Java in Using Oracle Autonomous Database Serverless for more information.The input geometry must be in JSON format. For information about using JSON data that is stored in Oracle Database, see Oracle Database JSON Developer's Guide.
For information about Spatial support for JSON, see JSON and GeoJSON Support in Oracle Spatial.
To convert an SDO_GEOMETRY object to JSON format, use the SDO_UTIL.TO_JSON or SDO_UTIL.TO_JSON_VARCHAR function.
Examples
The following example shows conversion to and from JSON format. (The example uses the definitions and data from Simple Example: Inserting_ Indexing_ and Querying Spatial Data, specifically the cola_b
geometry from the COLA_MARKETS table.)
DECLARE cola_b_geom SDO_GEOMETRY; returned_geom SDO_GEOMETRY; returned_json CLOB; BEGIN -- Populate geometry variable with cola market cols_b shape. SELECT c.shape into cola_b_geom FROM cola_markets c WHERE c.name = 'cola_b'; -- From geometry to JSON returned_json := SDO_UTIL.TO_JSON(cola_b_geom); -- From JSON to geometry returned_geom := SDO_UTIL.FROM_JSON(returned_json); END; /
The following example shows a JSON object that represents a specified geometry being converted back into SDO_GEOMETRY. (In this case the JSON reflects the cola_b
geometry from the COLA_MARKETS table, defined in Simple Example: Inserting_ Indexing_ and Querying Spatial Data.)
SELECT SDO_UTIL.FROM_JSON( '{"polygon": {"boundary": [{"line": {"datapoints": [[5.0, 1.0], [8.0, 1.0], [8.0, 6.0], [5.0, 7.0], [5.0, 1.0]]}}]}}') GEOM FROM DUAL; GEOM ------ SDO_GEOMETRY(2003, NULL, NULL, SDO_ELEM_INFO_ARRAY(1, 1003, 1), SDO_ORDINATE_ARRAY(5, 1, 8, 1, 8, 6, 5, 7, 5, 1))
Related Topics
Parent topic: SDO_UTIL Package (Utility)