Commit e521de7f authored by Benito van der Zander's avatar Benito van der Zander

add printed-json-format option

parent 947c89d5
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note [ <!ENTITY it-is-broken "working well"> ]>
<s>&it-is-broken;</s>
\ No newline at end of file
[
[
1,
2
],
5,
null,
7,
{
"v": 18
}
]
[
[
1,
2
],
5,
null,
"",
7,
{
"v": 18
}
]
[
[
1,
2
],
5,
"",
{
"v": 18
}
]
<title>{.}</title>
......@@ -120,14 +120,14 @@ tests/test.sh followCustomErrorHandling '<a/>' -f '{"url": "http://example.org"
#output formats
tests/test.sh adhoc1 tests/a.xml --extract "<a>{.}</a>*"
tests/test.sh xml1 tests/a.xml --extract "<a>{.}</a>*" --output-format xml-wrapped
tests/test.sh json1 tests/a.xml --extract "<a>{.}</a>*" --output-format json-wrapped
tests/test.sh json1 tests/a.xml --extract "<a>{.}</a>*" --output-format json #deprecated
tests/test.sh json1 tests/a.xml --extract "<a>{.}</a>*" --output-format json-wrapped
tests/test.sh json1 tests/a.xml --extract "<a>{.}</a>*" --output-format json #deprecated
tests/test.sh xmlraw1 tests/a.xml --extract "<a>{.}</a>*" --output-format xml
tests/test.sh htmlraw1 tests/a.xml --extract "<a>{.}</a>*" --output-format html
tests/test.sh bash1 tests/a.xml --extract "<a>{.}</a>*" --output-format bash
tests/test.sh cmd1 tests/a.xml --extract "<a>{.}</a>*" --output-format cmd
tests/test.sh xml1b tests/a.xml --output-format xml-wrapped --extract "<a>{.}</a>*"
tests/test.sh json1b tests/a.xml --output-format json-wrapped --extract "<a>{.}</a>*"
tests/test.sh json1b tests/a.xml --output-format json-wrapped --extract "<a>{.}</a>*"
tests/test.sh json1b tests/a.xml --output-format json --extract "<a>{.}</a>*" #deprecated
tests/test.sh xmlraw1b tests/a.xml --output-format xml --extract "<a>{.}</a>*"
tests/test.sh htmlraw1b tests/a.xml --output-format html --extract "<a>{.}</a>*"
......@@ -218,7 +218,8 @@ tests/test.sh cmd7 '<x>&nbsp;&auml;&nbsp&uuml&xyz;&123;&</x>' -e /x --output-for
tests/test.sh adhoc8 -e '(1,2)' -e 5 -e '()' -e 7 -e v:=18
tests/test.sh xml8 --output-format xml-wrapped -e '(1,2)' -e 5 -e '()' -e 7 -e v:=18
tests/test.sh json8 --output-format json-wrapped -e '(1,2)' -e 5 -e '()' -e 7 -e v:=18
tests/test.sh json8 --output-format json-wrapped --printed-json-format compact -e '(1,2)' -e 5 -e '()' -e 7 -e v:=18
tests/test.sh json8p --output-format json-wrapped -e '(1,2)' -e 5 -e '()' -e 7 -e v:=18
tests/test.sh xmlraw8 --output-format xml -e '(1,2)' -e 5 -e '()' -e 7 -e v:=18
tests/test.sh htmlraw8 --output-format html -e '(1,2)' -e 5 -e '()' -e 7 -e v:=18
tests/test.sh bash8 --output-format bash -e '(1,2)' -e 5 -e '()' -e 7 -e v:=18
......@@ -227,7 +228,8 @@ tests/test.sh cmd8 --output-format bash -e '(1,2)' -e 5 -e '()' -e 7 -e v:=18
tests/test.sh adhoc9 -e '(1,2)' -e 5 -e '""' -e v:=18
tests/test.sh xml9 --output-format xml-wrapped -e '(1,2)' -e 5 -e '""' -e v:=18
tests/test.sh json9 --output-format json-wrapped -e '(1,2)' -e 5 -e '""' -e v:=18
tests/test.sh json9 --output-format json-wrapped --printed-json-format compact -e '(1,2)' -e 5 -e '""' -e v:=18
tests/test.sh json9p --output-format json-wrapped -e '(1,2)' -e 5 -e '""' -e v:=18
tests/test.sh xmlraw9 --output-format xml -e '(1,2)' -e 5 -e '""' -e v:=18
tests/test.sh htmlraw9 --output-format html -e '(1,2)' -e 5 -e '""' -e v:=18
tests/test.sh bash9 --output-format bash -e '(1,2)' -e 5 -e '""' -e v:=18
......@@ -235,7 +237,8 @@ tests/test.sh cmd9 --output-format bash -e '(1,2)' -e 5 -e '""' -e v:=18
tests/test.sh adhoc9b --print-type-annotations -e '(1,2)' -e 5 -e '()' -e '""' -e 7 -e v:=18
tests/test.sh xml9b --output-format xml-wrapped --print-type-annotations -e '(1,2)' -e 5 -e '()' -e '""' -e 7 -e v:=18
tests/test.sh json9b --output-format json-wrapped --print-type-annotations -e '(1,2)' -e 5 -e '()' -e '""' -e 7 -e v:=18
tests/test.sh json9b --output-format json-wrapped --printed-json-format compact --print-type-annotations -e '(1,2)' -e 5 -e '()' -e '""' -e 7 -e v:=18
tests/test.sh json9bp --output-format json-wrapped --print-type-annotations -e '(1,2)' -e 5 -e '()' -e '""' -e 7 -e v:=18
tests/test.sh xmlraw9b --output-format xml --print-type-annotations -e '(1,2)' -e 5 -e '()' -e '""' -e 7 -e v:=18
#tests/test.sh htmlraw9b --output-format html --print-type-annotations -e '(1,2)' -e 5 -e '()' -e '""' -e 7 -e v:=18
tests/test.sh bash9b --output-format bash --print-type-annotations -e '(1,2)' -e 5 -e '()' -e '""' -e 7 -e v:=18
......@@ -261,8 +264,8 @@ tests/test.sh xmlraw11 --output-format xml --print-type-annotations -e '2,xs:int
tests/test.sh adhoc-json -e '[1,2,3,{"a": 123,"b":"c"}]'
tests/test.sh xml-json -e '[1,2,3,{"a": 123,"b":"c"}]' --output-format xml
tests/test.sh html-json -e '[1,2,3,{"a": 123,"b":"c"}]' --output-format html
tests/test.sh xmlw-json -e '[1,2,3,{"a": 123,"b":"c"}]' --output-format xml-wrapped
tests/test.sh jsonw-json -e '[1,2,3,{"a": 123,"b":"c"}]' --output-format json-wrapped
tests/test.sh xmlw-json -e '[1,2,3,{"a": 123,"b":"c"}]' --output-format xml-wrapped
tests/test.sh jsonw-json --printed-json-format compact -e '[1,2,3,{"a": 123,"b":"c"}]' --output-format json-wrapped
tests/test.sh bash-json -e '[1,2,3,{"a": 123,"b":"c"}]' --output-format bash
......
......@@ -793,6 +793,7 @@ TExtraction = class(TDataProcessing)
printVariables: set of (pvLog, pvCondensedLog, pvFinal);
printTypeAnnotations, hideVariableNames: boolean;
printedNodeFormat: TTreeNodeSerialization;
printedJSONFormat: (jisDefault, jisPretty, jisCompact);
inputFormat: TInputFormat;
......@@ -1772,6 +1773,13 @@ begin
'html': printedNodeFormat:=tnsHTML;
end;
if reader.read('printed-json-format', tempstr) then begin
case tempstr of
'pretty': printedJSONFormat := jisPretty;
'compact': printedJSONFormat := jisCompact;
end;
end;
reader.read('input-format', inputFormat);
end;
......@@ -2339,7 +2347,7 @@ procedure TExtraction.printExtractedValue(value: IXQValue; invariable: boolean);
end;
pvkObject, pvkArray: begin
if (outputFormat <> ofAdhoc) and not invariable then needRawWrapper;
result := escape(v.jsonSerialize(printedNodeFormat, not invariable));
result := escape(v.jsonSerialize(printedNodeFormat, (printedJSONFormat = jisPretty) or (not invariable and (printedJSONFormat <> jisCompact))));
end;
else if not printTypeAnnotations then begin
if (outputFormat <> ofAdhoc) and not invariable then needRawWrapper;
......@@ -2396,7 +2404,7 @@ begin
end;
end;
ofJsonWrapped: begin
wcolor(value.jsonSerialize(printedNodeFormat), cJSON);
wcolor(value.jsonSerialize(printedNodeFormat, printedJSONFormat <> jisCompact), cJSON);
end;
ofXMLWrapped: begin
wcolor(value.xmlSerialize(printedNodeFormat, 'seq', 'e', 'object'), cXML);
......@@ -2571,6 +2579,7 @@ begin
printTypeAnnotations := other.printTypeAnnotations;
hideVariableNames := other.hideVariableNames;
printedNodeFormat := other.printedNodeFormat;
printedJSONFormat := other.printedJSONFormat;
inputFormat := inputFormat;
end;
......@@ -3532,6 +3541,7 @@ begin
mycmdLine.declareString('variable','Declares a variable (value taken from environment if not given explicitely) (multiple variables are preliminary)');
mycmdLine.declareString('xmlns','Declares a namespace');
mycmdLine.declareString('printed-node-format', 'Format of an extracted node: text, html or xml');
mycmdline.declareString('printed-json-format', 'Format of JSON items: pretty or compact');
mycmdLine.declareString('output-format', 'Output format: adhoc (simple human readable), xml, html, xml-wrapped (machine readable version of adhoc), json-wrapped, bash (export vars to bash), or cmd (export vars to cmd.exe) ', 'adhoc');
mycmdLine.declareString('output-encoding', 'Character encoding of the output. utf-8, latin1, utf-16be, utf-16le, oem (windows console) or input (no encoding conversion)', 'utf-8');
mycmdLine.declareString('output-declaration', 'Header for the output. (e.g. <!DOCTYPE html>, default depends on output-format)', '');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment