Skip to content

Commit

Permalink
Merge pull request #299 from dsnz/develop_v3
Browse files Browse the repository at this point in the history
alias without {} for json string; updated README and version
  • Loading branch information
dsnz committed Mar 6, 2024
2 parents c55aa3b + 31a145b commit 2d7cdb9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
**PL/JSON** provides packages and APIs for dealing with JSON formatted data within PL/SQL code.
General information about JSON is available at http://www.json.org.

## Latest release 3.7.0 (2024-02-18)
## Latest release 3.7.1 (2024-03-06)

### What's new
Now **pljson_dyn** has the Oracle ORDS feature that when a column alias starts with **{}**
then the column is assumed to be a json string and it's not escaped so that is merges seamlessly within the surrounding JSON
(the initial **{}** is removed from the result element name)

This release contains a small but important improvement.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pljson",
"version": "3.7.0",
"version": "3.7.1",
"description": "A PL/SQL object for handling JSON data in Oracle stored procedures and tables.",
"main": "index.js",
"directories": {
Expand Down
50 changes: 30 additions & 20 deletions src/addons/pljson_dyn.package.sql
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ create or replace package body pljson_dyn as
read_varray pljson_varray;
read_narray pljson_narray;
dateformat_str varchar2(32767);
esc_p boolean;
str_esc_p boolean;
str_name varchar2(32767);
begin
if (cur_num is not null) then
l_cur := cur_num;
Expand Down Expand Up @@ -218,14 +219,16 @@ create or replace package body pljson_dyn as
inner_obj.put(l_dtbl(i).col_name, pljson_null()); --null
end if;
else
esc_p := true;
if (l_dtbl(i).col_name like '{}%') then
esc_p := false;
str_esc_p := true;
str_name := l_dtbl(i).col_name;
if (str_name like '{}%') then
str_esc_p := false;
str_name := substr(str_name, 3);
end if;
-- in the following call,
-- not esc_p will be true when esc_p is false and at the same time
-- unescaped_string_delim assumed to have default value ''
inner_obj.put(l_dtbl(i).col_name, pljson_string(l_val, esc => esc_p, unescaped_string_delim_p => not esc_p));
inner_obj.put(str_name, pljson_string(l_val, esc => str_esc_p, unescaped_string_delim_p => not str_esc_p));
end if;
--dbms_output.put_line(l_dtbl(i).col_name||' --> '||l_val||'varchar2' ||l_dtbl(i).col_type);
--handling number types
Expand Down Expand Up @@ -260,14 +263,16 @@ create or replace package body pljson_dyn as
inner_obj.put(l_dtbl(i).col_name, pljson_null());
end if;
else
esc_p := true;
if (l_dtbl(i).col_name like '{}%') then
esc_p := false;
str_esc_p := true;
str_name := l_dtbl(i).col_name;
if (str_name like '{}%') then
str_esc_p := false;
str_name := substr(str_name, 3);
end if;
-- in the following call,
-- not esc_p will be true when esc_p is false and at the same time
-- unescaped_string_delim assumed to have default value ''
inner_obj.put(l_dtbl(i).col_name, pljson_string(read_clob, esc => esc_p, unescaped_string_delim_p => not esc_p));
inner_obj.put(str_name, pljson_string(read_clob, esc => str_esc_p, unescaped_string_delim_p => not str_esc_p));
end if;
end if;
when l_dtbl(i).col_type = 113 then --blob
Expand Down Expand Up @@ -302,7 +307,7 @@ create or replace package body pljson_dyn as
inner_obj.check_for_duplicate := 1;
outer_list.append(inner_obj);
end loop;

dbms_sql.close_cursor(l_cur);
return outer_list;
end executeList;
Expand Down Expand Up @@ -330,7 +335,8 @@ create or replace package body pljson_dyn as
read_varray pljson_varray;
read_narray pljson_narray;
dateformat_str varchar2(32767);
esc_p boolean;
str_esc_p boolean;
str_name varchar2(32767);
begin
if (cur_num is not null) then
l_cur := cur_num;
Expand Down Expand Up @@ -405,14 +411,16 @@ create or replace package body pljson_dyn as
data_list.append(pljson_null()); --null
end if;
else
esc_p := true;
if (l_dtbl(i).col_name like '{}%') then
esc_p := false;
str_esc_p := true;
str_name := l_dtbl(i).col_name;
if (str_name like '{}%') then
str_esc_p := false;
str_name := substr(str_name, 3);
end if;
-- in the following call,
-- not esc_p will be true when esc_p is false and at the same time
-- unescaped_string_delim assumed to have default value ''
data_list.append(pljson_string(l_val, esc => esc_p, unescaped_string_delim_p => not esc_p));
data_list.append(pljson_string(l_val, esc => str_esc_p, unescaped_string_delim_p => not str_esc_p));
end if;
--dbms_output.put_line(l_dtbl(i).col_name||' --> '||l_val||'varchar2' ||l_dtbl(i).col_type);
--handling number types
Expand Down Expand Up @@ -446,14 +454,16 @@ create or replace package body pljson_dyn as
data_list.append(pljson_null());
end if;
else
esc_p := true;
if (l_dtbl(i).col_name like '{}%') then
esc_p := false;
str_esc_p := true;
str_name := l_dtbl(i).col_name;
if (str_name like '{}%') then
str_esc_p := false;
str_name := substr(str_name, 3);
end if;
-- in the following call,
-- not esc_p will be true when esc_p is false and at the same time
-- unescaped_string_delim assumed to have default value ''
data_list.append(pljson_string(read_clob, esc => esc_p, unescaped_string_delim_p => not esc_p));
data_list.append(pljson_string(read_clob, esc => str_esc_p, unescaped_string_delim_p => not str_esc_p));
end if;
end if;
when l_dtbl(i).col_type = 113 then --blob
Expand Down Expand Up @@ -487,7 +497,7 @@ create or replace package body pljson_dyn as
end loop;
inner_list_data.append(data_list);
end loop;

outer_obj.put('names', inner_list_names);
outer_obj.put('data', inner_list_data);
dbms_sql.close_cursor(l_cur);
Expand Down

0 comments on commit 2d7cdb9

Please sign in to comment.