Make JSON.parse of data in MoveBinaryData optional

This commit is contained in:
Jan Oberhauser 2019-11-01 11:07:17 +01:00
parent 7ebe09cec1
commit b16b664afa

View file

@ -170,6 +170,23 @@ export class MoveBinaryData implements INodeType {
default: false, default: false,
description: 'If the source key should be kept. By default does it get deleted.', description: 'If the source key should be kept. By default does it get deleted.',
}, },
{
displayName: 'JSON Parse',
name: 'jsonParse',
type: 'boolean',
displayOptions: {
show: {
'/mode': [
'binaryToJson',
],
'/setAllData': [
false
],
},
},
default: false,
description: 'Run JSON parse on the data to get propery object data.',
},
{ {
displayName: 'Mime Type', displayName: 'Mime Type',
name: 'mimeType', name: 'mimeType',
@ -235,15 +252,19 @@ export class MoveBinaryData implements INodeType {
continue; continue;
} }
const convertedValue = JSON.parse(new Buffer(value.data, 'base64').toString('ascii')); let convertedValue = new Buffer(value.data, 'base64').toString('utf8');
if (setAllData === true) { if (setAllData === true) {
// Set the full data // Set the full data
newItem.json = convertedValue; newItem.json = JSON.parse(convertedValue);
} else { } else {
// Does get added to existing data so copy it first // Does get added to existing data so copy it first
newItem.json = JSON.parse(JSON.stringify(item.json)); newItem.json = JSON.parse(JSON.stringify(item.json));
if (options.jsonParse) {
convertedValue = JSON.parse(convertedValue);
}
const destinationKey = this.getNodeParameter('destinationKey', itemIndex, '') as string; const destinationKey = this.getNodeParameter('destinationKey', itemIndex, '') as string;
set(newItem.json, destinationKey, convertedValue); set(newItem.json, destinationKey, convertedValue);
} }