You can tweak the behavior of PL/JSON by setting various variables in the packages. The following sections are a description of the possible adjustments you can do.
In the printer package you can edit the line break method to Linux, Windows or macOS style. You can also change the indentation to the tabular char, or change the number of spaces.
The parser is extended to accept more than just pure JSON. The variable
json_strict
is defaulted to false and can be set to true to
force PL/JSON to only accept proper JSON. The current
implementation allows input to contain comments with the
/* */
notation. Furthermore it extends the definition of a
string to allow single quotes and converts names into strings.
The grammar for names accepted by PL/JSON is:
name : (letter) ((letter| digits | us)*);
However, the values true
, false
and null
will not be handled as names.
Example of usage with the extended grammar:
{
abc : '123"'
}
Parsed and emitted:
{
"abc" : "123\""
}
Even though javascript functions are not a part of JSON, you might want to emit functions if your receiving client is a browser. This is how you do it:
declare
obj pljson := pljson();
begin
obj.put('test', pljson_value('function() {return 1;}', esc => false ));
obj.print;
end;
The output is:
{
"test": /**/function() {return 1;}/**/
}
Which is not valid JSON but will work in javascript.
The surrounding /**/
is a message to the parser to start and
stop building a unescaped pljson_value
string:
declare
obj pljson := pljson('{"test": /**/function() {return 1;}/**/}');
begin
obj.print;
end;
-- {
-- "test": /**/function() {return 1;}/**/
-- }