Bookshelf.js FindOrCreate method - bluebird

I have the following in a Bookshelf Model
create (data, options = {}) {
return this.forge(data)
.save(null, options);
},
findOne (data, options = {}) {
return this.forge(data).fetch(options);
},
findOrCreate (data, options = {}) {
let createOpts = _.clone(data);
let findOpts = _.pick(data, 'name', 'id');
return this.findOne(findOpts, options)
.then(model => {
return model ? model : this.create(createOpts, options);
});
}
I have a controller with a method that calls to the findOrCreate method like so:
function insertRows(ScenesCollection, Location) {
return config => {
const payload = config.payload;
const projectId = config.project.get('id');
const userId = config.userId;
let inserts = filterImportPayload(payload);
let inserted = [];
_.forEach(inserts, obj => {
let opts = extractOptions(obj, projectId);
let sceneOpts = _.omit(opts, 'location');
_.extend(sceneOpts, {
create_user: config.userId,
update_user: config.userId
});
if (obj.location) {
const locOpts = _.pick({
id: obj.location.value.id,
name: _.isObject(obj.location.value) ? undefined : obj.location.value,
project_id: projectId,
create_user: userId,
update_user: userId
}, _.identity);
inserted.push(Location.findOrCreate(locOpts).then(location => {
sceneOpts.location_id = location.get('id');
}).thenReturn(sceneOpts));
} else {
inserted.push(sceneOpts);
}
});
return Bluebird.all(inserted).then(inserts => {
config.inserted = ScenesCollection.forge(inserts).invokeThen('save');
return Bluebird.props(config);
});
}
}
And the payload that comes in from the POST request is
[{
"name": {
"value": "2a",
"type": "data"
},
"slugline": {
"value": "The Linten Bakery.",
"type": "data"
},
"description": {
"value": "Mary is a hastily prepared but surprisingly breakfast. :)",
"type": "data"
},
"story_day": {
"value": 2,
"type": "data"
},
"page_count": {
"value": 1.5,
"type": "data"
},
"location": {
"type": "matched",
"value": {
"id": 149
}
},
"day_night": {
"type": "matched",
"value": {
"id": 10
}
},
"int_ext": {
"type": "matched",
"value": {
"id": 26
}
},
"extras_count": {
"value": 3,
"type": "data"
},
"type": "insert"
}, {
"name": {
"value": "PU 11a",
"type": "data"
},
"slugline": {
"value": "Office. Not good. But worth it.asd",
"type": "data"
},
"description": {
"value": "asd",
"type": "data"
},
"story_day": {
"value": 1,
"type": "data"
},
"page_count": {
"value": 1,
"type": "data"
},
"location": {
"type": "matched",
"value": {
"id": 149
}
},
"day_night": {
"type": "matched",
"value": {
"id": 10
}
},
"int_ext": {
"value": null,
"type": "ignore"
},
"extras_count": {
"value": 16,
"type": "data"
},
"type": "insert"
}, {
"name": {
"value": "PU 1",
"type": "data"
},
"slugline": {
"value": "Hallwayadqwe",
"type": "data"
},
"description": {
"value": "Mary goes to the kitchennettie.ads",
"type": "data"
},
"story_day": {
"value": 1,
"type": "data"
},
"page_count": {
"value": 1.75,
"type": "data"
},
"location": {
"type": "matched",
"value": {
"id": 149
}
},
"day_night": {
"type": "matched",
"value": {
"id": 10
}
},
"int_ext": {
"type": "matched",
"value": {
"id": 26
}
},
"extras_count": {
"value": 1,
"type": "data"
},
"type": "insert"
}, {
"name": {
"value": "PU 11b",
"type": "data"
},
"slugline": {
"value": "Officeqe",
"type": "data"
},
"description": {
"value": "Extras enter office, causing commotionads",
"type": "data"
},
"story_day": {
"value": 1,
"type": "data"
},
"page_count": {
"value": 0.5,
"type": "data"
},
"location": {
"value": "The Cinema",
"type": "insert"
},
"day_night": {
"type": "matched",
"value": {
"id": 10
}
},
"int_ext": {
"type": "matched",
"value": {
"id": 26
}
},
"extras_count": {
"value": 15,
"type": "data"
},
"type": "insert"
}, {
"name": {
"value": "443",
"type": "data"
},
"slugline": {
"value": "Office",
"type": "data"
},
"description": {
"value": "Wide of Mary standing in what remains of the officeasd",
"type": "data"
},
"story_day": {
"value": "",
"type": "ignore"
},
"page_count": {
"value": 1,
"type": "data"
},
"location": {
"value": "Milwaukee General Hospital",
"type": "insert"
},
"day_night": {
"type": "matched",
"value": {
"id": 10
}
},
"int_ext": {
"type": "matched",
"value": {
"id": 26
}
},
"extras_count": {
"value": 0,
"type": "ignore"
},
"type": "insert"
}, {
"name": {
"value": "PU 6",
"type": "data"
},
"slugline": {
"value": "Office",
"type": "data"
},
"description": {
"value": "Mary walks up to office, out of breath. asd",
"type": "data"
},
"story_day": {
"value": 1,
"type": "data"
},
"page_count": {
"value": 0.5,
"type": "data"
},
"location": {
"value": "My Room",
"type": "insert"
},
"day_night": {
"type": "matched",
"value": {
"id": 10
}
},
"int_ext": {
"type": "matched",
"value": {
"id": 26
}
},
"extras_count": {
"value": "",
"type": "ignore"
},
"type": "insert"
}, {
"name": {
"value": "PU 9",
"type": "data"
},
"slugline": {
"value": "Office/radio",
"type": "data"
},
"description": {
"value": "Mary enjoying listening to her radio at a reasonable volume.ads",
"type": "data"
},
"story_day": {
"value": 1,
"type": "data"
},
"page_count": {
"value": 0.5,
"type": "data"
},
"location": {
"value": "My Room",
"type": "insert"
},
"day_night": {
"type": "matched",
"value": {
"id": 10
}
},
"int_ext": {
"type": "matched",
"value": {
"id": 26
}
},
"type": "insert"
}, {
"name": {
"value": "PU 8b",
"type": "data"
},
"slugline": {
"value": "Office",
"type": "data"
},
"description": {
"value": "Mary converses with Alice outside her officead",
"type": "data"
},
"story_day": {
"value": 1,
"type": "data"
},
"page_count": {
"value": 2.5,
"type": "data"
},
"location": {
"value": "The Cinema",
"type": "insert"
},
"day_night": {
"type": "matched",
"value": {
"id": 10
}
},
"int_ext": {
"type": "matched",
"value": {
"id": 26
}
},
"type": "insert"
}, {
"name": {
"value": "PU 5a",
"type": "data"
},
"slugline": {
"value": "Street",
"type": "data"
},
"description": {
"value": "Wide of mary and child with ballasd",
"type": "data"
},
"story_day": {
"value": 1,
"type": "data"
},
"page_count": {
"value": 1,
"type": "data"
},
"location": {
"value": "My Room",
"type": "insert"
},
"day_night": {
"type": "matched",
"value": {
"id": 11
}
},
"int_ext": {
"type": "matched",
"value": {
"id": 26
}
},
"extras_count": {
"value": 1,
"type": "data"
},
"type": "insert"
}, {
"name": {
"value": "3a",
"type": "data"
},
"slugline": {
"value": "Outside Door",
"type": "data"
},
"description": {
"value": "Mary exits the house",
"type": "data"
},
"story_day": {
"value": 1,
"type": "data"
},
"page_count": {
"value": 0.5,
"type": "data"
},
"location": {
"type": "matched",
"value": {
"id": 491
}
},
"day_night": {
"type": "matched",
"value": {
"id": 10
}
},
"int_ext": {
"type": "matched",
"value": {
"id": 26
}
},
"extras_count": {
"value": 0,
"type": "ignore"
},
"type": "insert"
}, {
"name": {
"value": "2b",
"type": "data"
},
"slugline": {
"value": "Mary's Kitchen",
"type": "data"
},
"description": {
"value": "Mary begins to prepare a second breakfast.",
"type": "data"
},
"story_day": {
"value": 1,
"type": "data"
},
"page_count": {
"value": 1.125,
"type": "data"
},
"day_night": {
"type": "matched",
"value": {
"id": 10
}
},
"int_ext": {
"type": "matched",
"value": {
"id": 27
}
},
"extras_count": {
"value": 1,
"type": "data"
},
"type": "insert"
}, {
"name": {
"value": "83",
"type": "data"
},
"slugline": {
"value": "Office",
"type": "data"
},
"description": {
"value": "Carsten enters Mary's office, informs her she will need to relocate downstairs.",
"type": "data"
},
"story_day": {
"value": 1,
"type": "data"
},
"page_count": {
"value": 0.5,
"type": "data"
},
"location": {
"value": "My Room",
"type": "insert"
},
"day_night": {
"type": "matched",
"value": {
"id": 10
}
},
"int_ext": {
"type": "matched",
"value": {
"id": 26
}
},
"extras_count": {
"value": 0,
"type": "ignore"
},
"type": "insert"
}, {
"name": {
"value": "333",
"type": "data"
},
"slugline": {
"value": "COLLISIUM WEST",
"type": "data"
},
"description": {
"value": "There is a large explosion and then people start running out of the building",
"type": "data"
},
"story_day": {
"value": 10,
"type": "data"
},
"page_count": {
"value": 0,
"type": "ignore"
},
"location": {
"value": "Milwaukee General Hospital",
"type": "insert"
},
"day_night": {
"value": null,
"type": "ignore"
},
"int_ext": {
"type": "matched",
"value": {
"id": 27
}
},
"extras_count": {
"value": 12,
"type": "data"
},
"type": "insert"
}, {
"name": {
"value": "43",
"type": "data"
},
"slugline": {
"value": "I love THAT",
"type": "data"
},
"description": {
"value": "bbg",
"type": "data"
},
"story_day": {
"value": 12,
"type": "data"
},
"page_count": {
"value": 0,
"type": "ignore"
},
"location": {
"value": "Milwaukee General Hospital",
"type": "insert"
},
"day_night": {
"type": "matched",
"value": {
"id": 11
}
},
"int_ext": {
"type": "matched",
"value": {
"id": 27
}
},
"extras_count": {
"value": 10,
"type": "data"
},
"type": "insert"
}]
The problem I am having is that the findOrCreate method is creating multiple records of the same location.

Related

What is the correct <object> to use to connect my elasticsearch repository to the INCEpTION NER annotation program

I have setup a local environment for text annotation and would like to use the INCEpTION application developed here: https://github.com/inception-project/inception/blob/main/CONTRIBUTORS.txt
When trying to connect to my repository I can connect and find documents using their example found here: https://inception-project.github.io/releases/22.1/docs/user-guide.html#sect_external-search-repos
But when trying to connect to my repository created and indexed with FSCrawler I can't get the search to work.
The mapping for the their example is:
{
"mappings": {
"_doc": {
"properties": {
"doc": {
"properties": {
"text": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"metadata": {
"properties": {
"language": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"source": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"timestamp": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"uri": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
}
and my index mapping is:
{
"mappings": {
"_doc": {
"dynamic_templates": [
{
"raw_as_text": {
"path_match": "meta.raw.*",
"mapping": {
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
},
"type": "text"
}
}
}
],
"properties": {
"attachment": {
"type": "binary"
},
"attributes": {
"properties": {
"group": {
"type": "keyword"
},
"owner": {
"type": "keyword"
}
}
},
"content": {
"type": "text"
},
"file": {
"properties": {
"checksum": {
"type": "keyword"
},
"content_type": {
"type": "keyword"
},
"created": {
"type": "date",
"format": "dateOptionalTime"
},
"extension": {
"type": "keyword"
},
"filename": {
"type": "keyword",
"store": true
},
"filesize": {
"type": "long"
},
"indexed_chars": {
"type": "long"
},
"indexing_date": {
"type": "date",
"format": "dateOptionalTime"
},
"last_accessed": {
"type": "date",
"format": "dateOptionalTime"
},
"last_modified": {
"type": "date",
"format": "dateOptionalTime"
},
"url": {
"type": "keyword",
"index": false
}
}
},
"meta": {
"properties": {
"altitude": {
"type": "text"
},
"author": {
"type": "text"
},
"comments": {
"type": "text"
},
"contributor": {
"type": "text"
},
"coverage": {
"type": "text"
},
"created": {
"type": "date",
"format": "dateOptionalTime"
},
"creator_tool": {
"type": "keyword"
},
"date": {
"type": "date",
"format": "dateOptionalTime"
},
"description": {
"type": "text"
},
"format": {
"type": "text"
},
"identifier": {
"type": "text"
},
"keywords": {
"type": "text"
},
"language": {
"type": "keyword"
},
"latitude": {
"type": "text"
},
"longitude": {
"type": "text"
},
"metadata_date": {
"type": "date",
"format": "dateOptionalTime"
},
"modifier": {
"type": "text"
},
"print_date": {
"type": "date",
"format": "dateOptionalTime"
},
"publisher": {
"type": "text"
},
"rating": {
"type": "byte"
},
"relation": {
"type": "text"
},
"rights": {
"type": "text"
},
"source": {
"type": "text"
},
"title": {
"type": "text"
},
"type": {
"type": "text"
}
}
},
"path": {
"properties": {
"real": {
"type": "keyword",
"fields": {
"fulltext": {
"type": "text"
},
"tree": {
"type": "text",
"analyzer": "fscrawler_path",
"fielddata": true
}
}
},
"root": {
"type": "keyword"
},
"virtual": {
"type": "keyword",
"fields": {
"fulltext": {
"type": "text"
},
"tree": {
"type": "text",
"analyzer": "fscrawler_path",
"fielddata": true
}
}
}
}
}
}
}
}
}
I can search both repositories fine from anywhere else using the standard _search, matching the "content" object
{
"metadata": {
"language": "en",
"source": "My favourite document collection",
"timestamp": "2011/11/11 11:11",
"uri": "http://the.internet.com/my/document/collection/document1.txt",
"title": "Cool Document Title"
},
"doc": {
"text": "This is a test Document"
}
}
The same query works on the example even when moving the example 1 level up =
{
"metadata": {
"language": "en",
"source": "My favourite document collection",
"timestamp": "2011/11/11 11:11",
"uri": "http://the.internet.com/my/document/collection/document1.txt",
"title": "Cool Document Title"
},
"doc": "This is a test Document"
}
}
Which object do I need to specify below in order to access the "content" object of my mapping
Chris
This is a functionality issue unfortunately.
mapping has to be very specific in order to use this, remapping (changing fscrawler mapping) does not work unless document mapping is very specific.
Simply changing fields and types does not work.
https://github.com/inception-project/inception/issues/2516

How to convert json schema in one form to other surported by cerberus?

How can we convert this schema to the below one:
{
"entityName": "Firm",
"attributes": [
{
"name": "FirmKey",
"rules": [
{
"type": "primaryKey",
"severity": "reject",
"operator": "",
"value": "1"
},
{
"type": "dataType",
"severity": "reject",
"operator": "",
"dataType": "int"
},
{
"type": "notNull",
"severity": "reject",
"operator": ""
}
]
},
{
"key": "attributedcfd6d27",
"name": "FirmName",
"unit": "",
"rules": [
{
"type": "dataType",
"severity": "reject",
"operator": "",
"dataType": "string"
}
],
}
}
converted:
{
"FirmKey":
{
"type": "list",
"schema":
{
"isint":true,
"isNull": NaN
}
},
"FirmName":
{
"type": "list",
"description": "Firm’s legal name",
"schema":
{
"type":"string",
"isNull": NaN
}
}
}

JMeter jp#gc JSON/YAML Path Assertion for an array

I'm trying to use jp#gc - JSON/YAML Path Assertion, when my Response Body is:
[
{
"label": "Alabama",
"value": "AL"
},
{
"label": "Alaska",
"value": "AK"
},
{
"label": "American Samoa",
"value": "AS"
},
{
"label": "Arizona",
"value": "AZ"
},
{
"label": "Arkansas",
"value": "AR"
},
{
"label": "California",
"value": "CA"
},
{
"label": "Colorado",
"value": "CO"
},
{
"label": "Connecticut",
"value": "CT"
},
{
"label": "Delaware",
"value": "DE"
},
{
"label": "District Of Columbia",
"value": "DC"
},
{
"label": "Federated States Of Micronesia",
"value": "FM"
},
{
"label": "Florida",
"value": "FL"
},
{
"label": "Georgia",
"value": "GA"
},
{
"label": "Guam",
"value": "GU"
},
{
"label": "Hawaii",
"value": "HI"
},
{
"label": "Idaho",
"value": "ID"
},
{
"label": "Illinois",
"value": "IL"
},
{
"label": "Indiana",
"value": "IN"
},
{
"label": "Iowa",
"value": "IA"
},
{
"label": "Kansas",
"value": "KS"
},
{
"label": "Kentucky",
"value": "KY"
},
{
"label": "Louisiana",
"value": "LA"
},
{
"label": "Maine",
"value": "ME"
},
{
"label": "Marshall Islands",
"value": "MH"
},
{
"label": "Maryland",
"value": "MD"
},
{
"label": "Massachusetts",
"value": "MA"
},
{
"label": "Michigan",
"value": "MI"
},
{
"label": "Minnesota",
"value": "MN"
},
{
"label": "Mississippi",
"value": "MS"
},
{
"label": "Missouri",
"value": "MO"
},
{
"label": "Montana",
"value": "MT"
},
{
"label": "Nebraska",
"value": "NE"
},
{
"label": "Nevada",
"value": "NV"
},
{
"label": "New Hampshire",
"value": "NH"
},
{
"label": "New Jersey",
"value": "NJ"
},
{
"label": "New Mexico",
"value": "NM"
},
{
"label": "New York",
"value": "NY"
},
{
"label": "North Carolina",
"value": "NC"
},
{
"label": "North Dakota",
"value": "ND"
},
{
"label": "Northern Mariana Islands",
"value": "MP"
},
{
"label": "Ohio",
"value": "OH"
},
{
"label": "Oklahoma",
"value": "OK"
},
{
"label": "Oregon",
"value": "OR"
},
{
"label": "Palau",
"value": "PW"
},
{
"label": "Pennsylvania",
"value": "PA"
},
{
"label": "Puerto Rico",
"value": "PR"
},
{
"label": "Rhode Island",
"value": "RI"
},
{
"label": "South Carolina",
"value": "SC"
},
{
"label": "South Dakota",
"value": "SD"
},
{
"label": "Tennessee",
"value": "TN"
},
{
"label": "Texas",
"value": "TX"
},
{
"label": "Utah",
"value": "UT"
},
{
"label": "Vermont",
"value": "VT"
},
{
"label": "Virgin Islands",
"value": "VI"
},
{
"label": "Virginia",
"value": "VA"
},
{
"label": "Washington",
"value": "WA"
},
{
"label": "West Virginia",
"value": "WV"
},
{
"label": "Wisconsin",
"value": "WI"
},
{
"label": "Wyoming",
"value": "WY"
}
]
Here is how is use the JSON/YAML Path Assertion:
but I'm getting Assertion failure:
The following setup should work for you:
More information:
JsonPath - Getting Started
Perl 5 Regex Cheat sheet
The New JSON/YAML Plugin - Using YAML in JMeter
Use JSON Assertion ( jp#gc - JSON/YAML is deprecated)
JSON start with array so use JSON Path
$.[0].label
You can also uncheck Match as regular expression

Error creating JSON Unexpected Character Sequence

I've been trying to create a basic json for our testes to throw up a machine a and when required. I got most of it done however I am getting the following errors:
Line 158 Unexpected character sequence in member name
Line 167 A member with the name 'Properties' already exists
I understand 67 needs to be unique, but everytime I change and remove the { it creates more errors.
And unexpected character is the { on line 157, which I'm guessing should be either a string, maybe?
My template is below.
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"virtualMachineName": {
"type": "string"
},
"offer": {
"type": "string",
"defaultvalue": "Windows",
"allowedValues": [
"windows",
"centos",
"RHEL"
]
},
"sku": {
"type": "string",
"defaultvalue": "2012-r2-datacenter",
"allowedValues": [
"2012-R2-Datacenter",
"2012-R2",
"68",
"72",
"73",
"74"
]
},
"virtualMachineSize": {
"type": "string",
"defaultvalue": "standard_A0",
"allowedValues": [
"Standard_A0",
"Standard_A1",
"standard_A2"
]
},
"adminUsername": {
"type": "string"
},
"ipaddress": {
"type": "string"
},
"virtualNetworkName": {
"type": "string"
},
"networkInterfaceName": {
"type": "string"
},
"networkSecurityGroupName": {
"type": "string"
},
"adminPassword": {
"type": "securestring"
},
"storageAccountName": {
"type": "string"
},
"diagnosticsStorageAccountName": {
"type": "string"
},
"diagnosticsStorageAccountId": {
"type": "string"
},
"subnetName": {
"type": "string"
},
"ContainerName": {
"type": "string"
},
"autoShutdownStatus": {
"type": "string"
},
"autoShutdownTime": {
"type": "string"
},
"autoShutdownTimeZone": {
"type": "string"
},
"autoShutdownNotificationStatus": {
"type": "string"
}
},
"variables": {
"vnetId": "[resourceId('avset','Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]",
"stdvhdcontainername": "[concat(parameters('Containername'))]",
"vmosidiskname": "[concat(parameters('virtualMachineName'),'-osdisk')]"
},
"resources": [
{
"name": "[parameters('virtualMachineName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2016-04-30-preview",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]"
],
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[concat (parameters('diagnosticsStorageAccountName')), ['blob']]"
}
},
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
}
]
},
"osProfile": {
"computerName": "[parameters('virtualMachineName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"offer": "[concat(parameters('offer'))]",
"sku": "[concat(parameters('offer'))]",
"version": "latest"
}
},
"osDisk": {
"vhd": {
"name": "[variables('vmosidiskname')]",
"uri": "[concat('http://', parameters('storageAccountName'), '.blob.core.windows.net/', variables('stdvhdcontainername'),'/', variables('vmosidiskname'), '.vhd')]"
},
"name": "[parameters('virtualMachineName')]"
},
"name": "[concat('shutdown-computevm-', parameters('virtualMachineName'))]",
"type": "Microsoft.DevTestLab/schedules",
"apiVersion": "2017-04-26-preview",
"location": "[parameters('location')]",
"properties": {
"status": "[parameters('autoShutdownStatus')]",
"taskType": "ComputeVmShutdownTask",
"dailyRecurrence": {
"time": "[parameters('autoShutdownTime')]"
},
"timeZoneId": "[parameters('autoShutdownTimeZone')]",
"targetResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]",
"notificationSettings": {
"status": "[parameters('autoShutdownNotificationStatus')]",
"timeInMinutes": "30"
},
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]"
]
},
{
"name": "[parameters('networkInterfaceName')]",
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2016-09-01",
"location": "[parameters('location')]"
},
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateipaddress": "[concat(parameters('ipaddress'))]",
"privateIPAllocationMethod": "static"
}
}
]
}
},
"outputs": [
{
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
}
}
]
}
]
}
Any pointers would be greatly appreciated.. thanks for your help :)
Params are below:)
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"value": "westeurope"
},
"virtualMachineName": {
"value": "cent-os-vm2"
},
"virtualMachineSize": {
"value": "Standard_A0"
},
"adminUsername": {
"value": "localadmin"
},
"virtualNetworkName": {
"value": "avset-vnet"
},
"networkInterfaceName": {
"value": "cent-os-vm01652"
},
"networkSecurityGroupName": {
"value": "cent-os-vm01-nsg"
},
"storageAccountName": {
"value": "avsetdisks419"
},
"diagnosticsStorageAccountName": {
"value": "avsetdiag112"
},
"diagnosticsStorageAccountId": {
"value": "avsetdiag117"
},
"subnetName": {
"value": "default"
},
"autoShutdownStatus": {
"value": "Enabled"
},
"autoShutdownTime": {
"value": "19:00"
},
"autoShutdownTimeZone": {
"value": "UTC"
},
"autoShutdownNotificationStatus": {
"value": "Disabled"
},
"ContainerName": {
"value": "vhd"
},
"offer": {
"value": "windows"
},
"sku": {
"value": "2012-R2-Datacenter"
},
"ipaddress": {
"value": "10.0.1.9"
}
}
}
There are many mistakes in your template. The following template should work.
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"virtualMachineName": {
"type": "string"
},
"offer": {
"type": "string",
"defaultvalue": "windows",
"allowedValues": [
"windows",
"centos",
"RHEL"
]
},
"sku": {
"type": "string",
"defaultvalue": "2012-R2-Datacenter",
"allowedValues": [
"2012-R2-Datacenter",
"2012-R2",
"68",
"72",
"73",
"74"
]
},
"virtualMachineSize": {
"type": "string",
"defaultvalue": "Standard_A0",
"allowedValues": [
"Standard_A0",
"Standard_A1",
"standard_A2"
]
},
"adminUsername": {
"type": "string"
},
"ipaddress": {
"type": "string"
},
"virtualNetworkName": {
"type": "string"
},
"networkInterfaceName": {
"type": "string"
},
"networkSecurityGroupName": {
"type": "string"
},
"adminPassword": {
"type": "securestring"
},
"storageAccountName": {
"type": "string"
},
"diagnosticsStorageAccountName": {
"type": "string"
},
"diagnosticsStorageAccountId": {
"type": "string"
},
"subnetName": {
"type": "string"
},
"ContainerName": {
"type": "string"
},
"autoShutdownStatus": {
"type": "string"
},
"autoShutdownTime": {
"type": "string"
},
"autoShutdownTimeZone": {
"type": "string"
},
"autoShutdownNotificationStatus": {
"type": "string"
}
},
"variables": {
"vnetId": "[resourceId('avset','Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]",
"stdvhdcontainername": "[concat(parameters('Containername'))]",
"vmosidiskname": "[concat(parameters('virtualMachineName'),'-osdisk')]"
},
"resources": [
{
"name": "[parameters('virtualMachineName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2016-04-30-preview",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]"
],
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[concat (parameters('diagnosticsStorageAccountName')), ['blob']]"
}
},
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
}
]
},
"osProfile": {
"computerName": "[parameters('virtualMachineName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"offer": "[concat(parameters('offer'))]",
"sku": "[concat(parameters('offer'))]",
"version": "latest"
}
},
"osDisk": {
"vhd": {
"name": "[variables('vmosidiskname')]",
"uri": "[concat('http://', parameters('storageAccountName'), '.blob.core.windows.net/', variables('stdvhdcontainername'),'/', variables('vmosidiskname'), '.vhd')]"
},
"name": "[parameters('virtualMachineName')]"
}
}
},
{
"name": "[concat('shutdown-computevm-', parameters('virtualMachineName'))]",
"type": "Microsoft.DevTestLab/schedules",
"apiVersion": "2017-04-26-preview",
"location": "[parameters('location')]",
"properties": {
"status": "[parameters('autoShutdownStatus')]",
"taskType": "ComputeVmShutdownTask",
"dailyRecurrence": {
"time": "[parameters('autoShutdownTime')]"
},
"timeZoneId": "[parameters('autoShutdownTimeZone')]",
"targetResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]",
"notificationSettings": {
"status": "[parameters('autoShutdownNotificationStatus')]",
"timeInMinutes": "30"
},
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]"
]
}
},
{
"name": "[parameters('networkInterfaceName')]",
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2016-09-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateipaddress": "[concat(parameters('ipaddress'))]",
"privateIPAllocationMethod": "static"
}
}
]
}
}
],
"outputs": {
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
}
}
}
In line 162, it lost a ,. Resource Microsoft.Compute/virtualMachines,Microsoft.DevTestLab/schedules,Microsoft.Network/networkInterfaces are in parallel. But in your template, Microsoft.Compute/virtualMachines contains others, so you get error log with the name 'Properties' already exists.
Note: You also need check your default value. Please note that case sensitive.
Update:
Ipconfigurations is wrong, it should like below:
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
Update 2:
The template.json and parameters.json works for me. Maybe you could modify your template according to this example.

JSON (from HTML Table) to CSV

I am working with a reports API from an Application which converts an HTML table into JSON using a method very similar to that shown in posts in Stack Overflow (example: HTML Table to JSON).
The JSON has an array of columns (for the NAMES of VALUES), then there is an array of rows which contain cells (for the VALUES).
I want to map this report to a canonical data model but it is horrible to work with. What I want to do is run some sort of script on the JSON which reverse what the original script put in place and turns it into an array that contains individual records, much like the rows of a CSV file.
Here's an example of a report I am referring to - horrible isn't it :)
My Question
Is there a way of turning this format of JSON (where it has an array for column names, an array for sections and inside an array of rows which relate to the column names), into a table of some sort?
{
"Header": {
"Time": "2016-03-30T16:10:19-07:00",
"ReportName": "GeneralLedger",
"ReportBasis": "Accrual",
"StartPeriod": "2016-01-01",
"EndPeriod": "2016-03-31",
"Currency": "GBP",
"Option": [
{
"Name": "NoReportData",
"Value": "false"
}
]
},
"Columns": {
"Column": [
{
"ColTitle": "Date",
"ColType": "tx_date"
},
{
"ColTitle": "Transaction Type",
"ColType": "txn_type"
},
{
"ColTitle": "No.",
"ColType": "doc_num"
},
{
"ColTitle": "Name",
"ColType": "name"
},
{
"ColTitle": "Memo/Description",
"ColType": "memo"
},
{
"ColTitle": "Split",
"ColType": "split_acc"
},
{
"ColTitle": "Amount",
"ColType": "subt_nat_amount"
},
{
"ColTitle": "Balance",
"ColType": "rbal_nat_amount"
}
]
},
"Rows": {
"Row": [
{
"Header": {
"ColData": [
{
"value": "Current",
"id": "144"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Bill Payment (Cheque)",
"id": "181"
},
{
"value": "1"
},
{
"value": "Teddy's T Shirt Supplier",
"id": "70"
},
{
"value": "104478"
},
{
"value": "Creditors",
"id": "138"
},
{
"value": "-600.0"
},
{
"value": "-600.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Bill Payment (Cheque)",
"id": "184"
},
{
"value": "2"
},
{
"value": "Teddy's T Shirt Supplier",
"id": "70"
},
{
"value": "104478"
},
{
"value": "Creditors",
"id": "138"
},
{
"value": "-120.0"
},
{
"value": "-720.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Deposit",
"id": "180"
},
{
"value": ""
},
{
"value": "",
"id": ""
},
{
"value": "Opening Balance"
},
{
"value": "Opening Balance Equity",
"id": "137"
},
{
"value": "2400.0"
},
{
"value": "1680.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-23"
},
{
"value": "Payment",
"id": "186"
},
{
"value": "345678"
},
{
"value": "Maxamillion Enterprises",
"id": "68"
},
{
"value": ""
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "216.0"
},
{
"value": "1896.0"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total for Current"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": "1896.0"
},
{
"value": ""
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "Debtors",
"id": "140"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "176"
},
{
"value": "1014"
},
{
"value": "Maxamillion Enterprises",
"id": "68"
},
{
"value": ""
},
{
"value": "-Split-",
"id": ""
},
{
"value": "216.0"
},
{
"value": "216.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "179"
},
{
"value": "1015"
},
{
"value": "Hope Reality Limited",
"id": "69"
},
{
"value": ""
},
{
"value": "-Split-",
"id": ""
},
{
"value": "108.0"
},
{
"value": "324.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-23"
},
{
"value": "Payment",
"id": "186"
},
{
"value": "345678"
},
{
"value": "Maxamillion Enterprises",
"id": "68"
},
{
"value": ""
},
{
"value": "Current",
"id": "144"
},
{
"value": "-216.0"
},
{
"value": "108.0"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total for Debtors"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": "108.0"
},
{
"value": ""
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "Stock Asset",
"id": "136"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "2016-03-01"
},
{
"value": "Stock Starting Value",
"id": "173"
},
{
"value": "START"
},
{
"value": "",
"id": ""
},
{
"value": "Round Neck T Shirt - Opening stock and value"
},
{
"value": "Opening Balance Equity",
"id": "137"
},
{
"value": "0.0"
},
{
"value": "0.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "179"
},
{
"value": "1015"
},
{
"value": "Hope Reality Limited",
"id": "69"
},
{
"value": "Round Neck T Shirt"
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "-12.0"
},
{
"value": "-12.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "176"
},
{
"value": "1014"
},
{
"value": "Maxamillion Enterprises",
"id": "68"
},
{
"value": "Round Neck T Shirt"
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "-24.0"
},
{
"value": "-36.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Stock Qty Adjust",
"id": "177"
},
{
"value": "2"
},
{
"value": "",
"id": ""
},
{
"value": ""
},
{
"value": "Stock Shrinkage",
"id": "141"
},
{
"value": "0.0"
},
{
"value": "-36.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Stock Qty Adjust",
"id": "182"
},
{
"value": "3"
},
{
"value": "",
"id": ""
},
{
"value": ""
},
{
"value": "Stock Shrinkage",
"id": "141"
},
{
"value": "-36.0"
},
{
"value": "-72.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Stock Qty Adjust",
"id": "182"
},
{
"value": "3"
},
{
"value": "",
"id": ""
},
{
"value": ""
},
{
"value": "Stock Shrinkage",
"id": "141"
},
{
"value": "-564.0"
},
{
"value": "-636.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Stock Qty Adjust",
"id": "177"
},
{
"value": "2"
},
{
"value": "",
"id": ""
},
{
"value": ""
},
{
"value": "Stock Shrinkage",
"id": "141"
},
{
"value": "600.0"
},
{
"value": "-36.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Stock Qty Adjust",
"id": "182"
},
{
"value": "3"
},
{
"value": "",
"id": ""
},
{
"value": ""
},
{
"value": "Stock Shrinkage",
"id": "141"
},
{
"value": "0.0"
},
{
"value": "-36.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Bill",
"id": "178"
},
{
"value": ""
},
{
"value": "Teddy's T Shirt Supplier",
"id": "70"
},
{
"value": "Round Neck T Shirt"
},
{
"value": "Creditors",
"id": "138"
},
{
"value": "600.0"
},
{
"value": "564.0"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total for Stock Asset"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": "564.0"
},
{
"value": ""
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "Creditors",
"id": "138"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Bill Payment (Cheque)",
"id": "181"
},
{
"value": "1"
},
{
"value": "Teddy's T Shirt Supplier",
"id": "70"
},
{
"value": ""
},
{
"value": "Current",
"id": "144"
},
{
"value": "-600.0"
},
{
"value": "-600.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Bill Payment (Cheque)",
"id": "184"
},
{
"value": "2"
},
{
"value": "Teddy's T Shirt Supplier",
"id": "70"
},
{
"value": ""
},
{
"value": "Current",
"id": "144"
},
{
"value": "-120.0"
},
{
"value": "-720.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Bill",
"id": "185"
},
{
"value": ""
},
{
"value": "British Power",
"id": "72"
},
{
"value": ""
},
{
"value": "Utilities",
"id": "129"
},
{
"value": "192.15"
},
{
"value": "-527.85"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Bill",
"id": "183"
},
{
"value": ""
},
{
"value": "Printing Ink Supplies",
"id": "71"
},
{
"value": ""
},
{
"value": "-Split-",
"id": ""
},
{
"value": "1920.0"
},
{
"value": "1392.15"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Bill",
"id": "178"
},
{
"value": ""
},
{
"value": "Teddy's T Shirt Supplier",
"id": "70"
},
{
"value": ""
},
{
"value": "Stock Asset",
"id": "136"
},
{
"value": "720.0"
},
{
"value": "2112.15"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total for Creditors"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": "2112.15"
},
{
"value": ""
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "VAT Control",
"id": "142"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "176"
},
{
"value": "1014"
},
{
"value": "Maxamillion Enterprises",
"id": "68"
},
{
"value": ""
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "36.0"
},
{
"value": "36.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "179"
},
{
"value": "1015"
},
{
"value": "Hope Reality Limited",
"id": "69"
},
{
"value": ""
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "18.0"
},
{
"value": "54.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Bill",
"id": "185"
},
{
"value": ""
},
{
"value": "British Power",
"id": "72"
},
{
"value": ""
},
{
"value": "Creditors",
"id": "138"
},
{
"value": "-9.15"
},
{
"value": "44.85"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Bill",
"id": "183"
},
{
"value": ""
},
{
"value": "Printing Ink Supplies",
"id": "71"
},
{
"value": ""
},
{
"value": "Creditors",
"id": "138"
},
{
"value": "-320.0"
},
{
"value": "-275.15"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Bill",
"id": "178"
},
{
"value": ""
},
{
"value": "Teddy's T Shirt Supplier",
"id": "70"
},
{
"value": ""
},
{
"value": "Creditors",
"id": "138"
},
{
"value": "-120.0"
},
{
"value": "-395.15"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total for VAT Control"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": "-395.15"
},
{
"value": ""
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "Opening Balance Equity",
"id": "137"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "2016-03-01"
},
{
"value": "Stock Starting Value",
"id": "173"
},
{
"value": "START"
},
{
"value": "",
"id": ""
},
{
"value": "Round Neck T Shirt - Opening stock and value"
},
{
"value": "Stock Asset",
"id": "136"
},
{
"value": "0.0"
},
{
"value": "0.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-17"
},
{
"value": "Deposit",
"id": "180"
},
{
"value": ""
},
{
"value": "",
"id": ""
},
{
"value": ""
},
{
"value": "Current",
"id": "144"
},
{
"value": "2400.0"
},
{
"value": "2400.0"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total for Opening Balance Equity"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": "2400.0"
},
{
"value": ""
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "Sales of Product Income",
"id": "133"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "179"
},
{
"value": "1015"
},
{
"value": "Hope Reality Limited",
"id": "69"
},
{
"value": "Round Neck T Shirt"
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "60.0"
},
{
"value": "60.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "176"
},
{
"value": "1014"
},
{
"value": "Maxamillion Enterprises",
"id": "68"
},
{
"value": "Round Neck T Shirt"
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "120.0"
},
{
"value": "180.0"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total for Sales of Product Income"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": "180.0"
},
{
"value": ""
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "Services",
"id": "131"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "176"
},
{
"value": "1014"
},
{
"value": "Maxamillion Enterprises",
"id": "68"
},
{
"value": "Print on Pocket"
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "60.0"
},
{
"value": "60.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "179"
},
{
"value": "1015"
},
{
"value": "Hope Reality Limited",
"id": "69"
},
{
"value": "Print on Pocket"
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "30.0"
},
{
"value": "90.0"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total for Services"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": "90.0"
},
{
"value": ""
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "Cost of sales",
"id": "134"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "176"
},
{
"value": "1014"
},
{
"value": "Maxamillion Enterprises",
"id": "68"
},
{
"value": "Round Neck T Shirt"
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "24.0"
},
{
"value": "24.0"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "2016-03-16"
},
{
"value": "Invoice",
"id": "179"
},
{
"value": "1015"
},
{
"value": "Hope Reality Limited",
"id": "69"
},
{
"value": "Round Neck T Shirt"
},
{
"value": "Debtors",
"id": "140"
},
{
"value": "12.0"
},
{
"value": "36.0"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total for Cost of sales"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": "36.0"
},
{
"value": ""
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "Stock Shrinkage",
"id": "141"
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
},
{
"value": ""
}
]
}
etc. I had to cut this JSON short, limited to 30000 characters.
What have you tried so far? This seems pretty straightforward. To get the rows into an array format you would do something like the following:
var data = {
"Header": {
"Time": "2016-03-30T16:10:19-07:00",
"ReportName": "GeneralLedger",
"ReportBasis": "Accrual",
"StartPeriod": "2016-01-01",
"EndPeriod": "2016-03-31",
"Currency": "GBP",
"Option": [{
"Name": "NoReportData",
"Value": "false"
}]
},
"Columns": {
"Column": [{
"ColTitle": "Date",
"ColType": "tx_date"
}, {
"ColTitle": "Transaction Type",
"ColType": "txn_type"
}, {
"ColTitle": "No.",
"ColType": "doc_num"
}, {
"ColTitle": "Name",
"ColType": "name"
}, {
"ColTitle": "Memo/Description",
"ColType": "memo"
}, {
"ColTitle": "Split",
"ColType": "split_acc"
}, {
"ColTitle": "Amount",
"ColType": "subt_nat_amount"
}, {
"ColTitle": "Balance",
"ColType": "rbal_nat_amount"
}]
},
"Rows": {
"Row": [{
"Header": {
"ColData": [{
"value": "Current",
"id": "144"
}, {
"value": ""
}, {
"value": ""
}, {
"value": ""
}, {
"value": ""
}, {
"value": ""
}, {
"value": ""
}, {
"value": ""
}]
},
"Rows": {
"Row": [{
"ColData": [{
"value": "2016-03-16"
}, {
"value": "Bill Payment (Cheque)",
"id": "181"
}, {
"value": "1"
}, {
"value": "Teddy's T Shirt Supplier",
"id": "70"
}, {
"value": "104478"
}, {
"value": "Creditors",
"id": "138"
}, {
"value": "-600.0"
}, {
"value": "-600.0"
}],
"type": "Data"
}, {
"ColData": [{
"value": "2016-03-17"
}, {
"value": "Bill Payment (Cheque)",
"id": "184"
}, {
"value": "2"
}, {
"value": "Teddy's T Shirt Supplier",
"id": "70"
}, {
"value": "104478"
}, {
"value": "Creditors",
"id": "138"
}, {
"value": "-120.0"
}, {
"value": "-720.0"
}],
"type": "Data"
}, {
"ColData": [{
"value": "2016-03-17"
}, {
"value": "Deposit",
"id": "180"
}, {
"value": ""
}, {
"value": "",
"id": ""
}, {
"value": "Opening Balance"
}, {
"value": "Opening Balance Equity",
"id": "137"
}, {
"value": "2400.0"
}, {
"value": "1680.0"
}],
"type": "Data"
}, {
"ColData": [{
"value": "2016-03-23"
}, {
"value": "Payment",
"id": "186"
}, {
"value": "345678"
}, {
"value": "Maxamillion Enterprises",
"id": "68"
}, {
"value": ""
}, {
"value": "Debtors",
"id": "140"
}, {
"value": "216.0"
}, {
"value": "1896.0"
}],
"type": "Data"
}]
}
}]
}
};
function parse(data) {
var rows = [],
row, curRow, rowSegment;
for (var i = 0; i < data.Rows.Row.length; ++i) {
rowSegment = data.Rows.Row[i].Rows.Row;
for (var j = 0; j < rowSegment.length; ++j) {
row = [];
curRow = rowSegment[j].ColData;
for (var x = 0; x < curRow.length; ++x) {
row.push(curRow[x].value);
}
rows.push(row);
}
}
return rows;
}
var parsed = parse(data);
var rowEl, outEl = document.getElementById('html-out'),
val;
for (var i = 0; i < parsed.length; ++i) {
rowEl = document.createElement("div");
rowEl.setAttribute("class", "row");
rowEl.appendChild(document.createTextNode(parsed[i].join(', ')));
outEl.appendChild(rowEl);
}
<div id="html-out"></div>
Also, you would probably want to add the columns as the first row but this looks like it would get you the CSV-type data you are going for.