I'm trying to convert 7z file content list to json and can't fix missing separator between output converted blocks.
I'm little bit newbie in json conversion, but found that jq could do the job. I read the jq documentation and found examples inside here and there also elsewhere without solution.
Please find the use case:
The command line:
jq -f pf_7z.jq -RThe input file demo.lst:
Date Time Attr Size Compressed Name ------------------- ----- ------------ ------------ ------------------------ 2018-06-23 14:02:16 D.... 0 0 Installer 2018-06-23 14:02:16 ..... 3381 1157 Installer\Readme 2018-06-23 14:02:16 ..... 4646 1157 Installer\License.txt 2018-06-23 14:02:16 ..... 138892 136152 Installer\Setup.exe
The filter file pf7z.jq:
def parse: def parse_line: . | map(match("(\\d+-\\d+-\\d+) (\\d+:\\d+:\\d+) (D|.).* +(\\d+) +(\\d+) +(.*\\\\)([^\\\\]*)\\.(.*)")) | .[] | ({ "date" :(.captures[0].string), "time" :(.captures[1].string), "attr" :(.captures[2].string), "size" :(.captures[3].string), "path" :(.captures[5].string), "name" :(.captures[6].string), "extn" :(.captures[7].string) }); split("\n") | ( {} + (parse_line)); parse
The expected result should be:
{ "date": "2018-06-23", "time": "14:02:16", "attr": ".", "size": "4646", "path": "Installer\", "name": "License", "extn": "txt" }, { "date": "2018-06-23", "time": "14:02:16", "attr": ".", "size": "138892", "path": "Installer\", "name": "Setup", "extn": "exe" }
And I only got :
{ "date": "2018-06-23", "time": "14:02:16", "attr": ".", "size": "4646", "path": "Installer\", "name": "License", "extn": "txt" } { "date": "2018-06-23", "time": "14:02:16", "attr": ".", "size": "138892", "path": "Installer\", "name": "Setup", "extn": "exe" }
without the comma separator between blocks.
Thanks ;-)