Search code examples
oracle-databaseoracle-ords

ORDS Oracle REST Data Services - Capitalize JSON KEYS


I'm learning how ORDS works and I would like to understand if it is possible to UpperCase the JSON key in the response.

I was looking for some configuration options in Oracle documentationm for this, but I was not able to find anything.

Thanks


Solution

  • Our Oracle {JSON} standard mandates lowercase attributes. There is no way to tell ORDS to generate output with uppercase JSON.

    BUT.

    If you generate the JSON yourself, you can have your ORDS GET HANDLER defined with a source type of 'Media Resource' and then I can do something like this.

    -- Generated by Oracle SQL Developer REST Data Services 18.2.0.176.0254
    -- Exported REST Definitions from ORDS Schema Version 17.4.1.353.06.48
    -- Schema: HR   Date: Thu Jun 28 07:55:08 EDT 2018
    --
    BEGIN
      ORDS.ENABLE_SCHEMA(
          p_enabled             => TRUE,
          p_schema              => 'HR',
          p_url_mapping_type    => 'BASE_PATH',
          p_url_mapping_pattern => 'hr',
          p_auto_rest_auth      => FALSE);    
    
      ORDS.DEFINE_MODULE(
          p_module_name    => 'test2',
          p_base_path      => '/test2/',
          p_items_per_page =>  25,
          p_status         => 'PUBLISHED',
          p_comments       => NULL);      
      ORDS.DEFINE_TEMPLATE(
          p_module_name    => 'test2',
          p_pattern        => 'rawjson',
          p_priority       => 0,
          p_etag_type      => 'HASH',
          p_etag_query     => NULL,
          p_comments       => NULL);
      ORDS.DEFINE_HANDLER(
          p_module_name    => 'test2',
          p_pattern        => 'rawjson',
          p_method         => 'GET',
          p_source_type    => 'resource/lob',
          p_items_per_page =>  25,
          p_mimes_allowed  => '',
          p_comments       => NULL,
          p_source         => 
    'SELECT ''application/json'', upper(json_doc)
    from json_play'
          );
      ORDS.DEFINE_TEMPLATE(
          p_module_name    => 'test2',
          p_pattern        => 'rawtext',
          p_priority       => 0,
          p_etag_type      => 'HASH',
          p_etag_query     => NULL,
          p_comments       => NULL);
      ORDS.DEFINE_HANDLER(
          p_module_name    => 'test2',
          p_pattern        => 'rawtext',
          p_method         => 'GET',
          p_source_type    => 'plsql/block',
          p_items_per_page =>  25,
          p_mimes_allowed  => '',
          p_comments       => NULL,
          p_source         => 
    'begin
       owa_util.status_line (200, '''', false);
       OWA_UTIL.MIME_HEADER (''text/plain'', TRUE);
        HTP.PRN ('{"WHATEVER": 0}');
    end;'
          );
    
      COMMIT; 
    END;
    

    So in first service, I'm querying an existing JSON doc stored in a CLOB, and simply upper casing the content.

    In the 2nd service, I'm writing my own output.

    Querying an existing JSON doc and returning the text, unformatted by ORDS

    enter image description here

    Generating my own response

    enter image description here