I’m trying to configure a procedure to output a file that requires almost no post-processing before being used.
The code I thought would work is:
local dataset,dataitem,startCode,endCode
arraybuild dataitem,¶,'',
'['+
str(«Check #»)+',"'+
datepattern(«Date»,'YYYY/MM/DD')+'","'+
replace(«Vendor»,'&','&')+'","'+
replace(«Description»,'&','&')+'","'+
pattern(«Check total»,'(#.,##)')+'"],'
dataset={<DATA>}
startCode = '{' + lf() + '"data": [' + lf()
endCode = lf() + ']' + lf() + '}
filesave 'linefeed.json', startCode + replace(dataset,'<DATA>',dataitem) + endCode
After opening linefeed.json, I can see that BBEdit thinks it is a file with Unix linefeeds. However, the character between each record is not a linefeed but some strange “special character” that BBEdit does not recognize. All the lines containing records are run together with that special character between them (shown as • below).
{
"data": [
[112149,"2015/06/03","000003 SO. CAL. ASSOC. OF GOVERNMENTS","ASSESSMENTS FOR FY 2015-16","6,644.00 "],•[96739,"2012/10/10","000009 KAREN KELLEY","EXPENSE REIMB.","19.04 "],•
// etc.
]}
I then tried replacing that first lf() with cr():
local dataset,dataitem,startCode,endCode
arraybuild dataitem,¶,'',
'['+
str(«Check #»)+',"'+
datepattern(«Date»,'YYYY/MM/DD')+'","'+
replace(«Vendor»,'&','&')+'","'+
replace(«Description»,'&','&')+'","'+
pattern(«Check total»,'(#.,##)')+'"],'
dataset={<DATA>}
startCode = '{' + cr() + '"data": [' + lf()
endCode = lf() + ']' + lf() + '}'
filesave 'carriagereturn.json', startCode + replace(dataset,'<DATA>',dataitem) + endCode
Replacing only that first lf() with cr() results in a file that BBEdit thinks is a Legacy Mac file with carriage returns, but there are no unrecognized characters, so the file displays as expected.
{
"data": [
[112149,"2015/06/03","000003 SO. CAL. ASSOC. OF GOVERNMENTS","ASSESSMENTS FOR FY 2015-16","6,644.00 "],
[96739,"2012/10/10","000009 KAREN KELLEY","EXPENSE REIMB.","19.04 "],
// etc.
]
}
Note that in both cases, the leading and trailing linefeeds display correctly:
{
"data": [
// data removed here
]
}
I must be missing something simple, but I can’t figure out what.
Obviously, I can use the cr() version, but it bugs me that I can’t figure out how to construct this procedure correctly.