jsonpath query for reading json's child elements - json

I'm trying to read element's values.
For test purposes I was trying to read account_name element value.
I've tried this
jsonloop query = "data/ads/data/insights/data[*]"
account_name = "$.data.ads.data.insights.data.[*].account_name"
But not getting result. Apart from this I've googled alot and my logic seems to be okay..but I dont know where am doing wrong.
{
"data": [{
"id": "act_78425484545145418"
}, {
"id": "act_87814545415645416"
}, {
"ads": {
"data": [{
"insights": {
"data": [{
"account_name": "Emirates WW",
"campaign_name": "FR_Ozone_aug",
"adset_name": "Android",
"ad_name": "C_mail_9sept",
"spend": 12.2,
"impressions": "1146",
"clicks": "16",
"_store_clicks": "0",
"inline_click_pointss": "16",
"actions": [{
"action_type": "custom_event._activate_",
"value": 2
}, {
"action_type": "custom_event.other",
"value": 1
}, {
"action_type": "click_points",
"value": 16
}, {
"action_type": "__install",
"value": 1
}, {
"action_type": "offsite_points.view_content_points",
"value": 25
}, {
"action_type": "post_points",
"value": 16
}, {
"action_type": "post_points",
"value": 16
}, {
"action_type": "offsite_points",
"value": 25
}, {
"action_type": "custom_event",
"value": 3
}],
"date_start": "2016-09-09",
"date_stop": "2016-09-19"
}],
"paging": {
"cursors": {
"before": "ADZZZZ",
"after": "ADZZZZ"
}
}
},
"id": "6054027758549"
}, {
"insights": {
"data": [{
"account_name": "Emirates WW",
"campaign_name": "FR_Ozone_aug",
"adset_name": "Reta_Phy_iOS",
"ad_name": "Council_email_9sept",
"spend": 10.13,
"impressions": "1004",
"clicks": "10",
"_store_clicks": "8",
"inline_click_pointss": "10",
"actions": [{
"action_type": "click_points",
"value": 10
}, {
"action_type": "offsite_points.view_content_points",
"value": 38
}, {
"action_type": "post_points",
"value": 10
}, {
"action_type": "post_points",
"value": 10
}, {
"action_type": "offsite_points",
"value": 38
}],
"date_start": "2016-09-09",
"date_stop": "2016-09-19"
}],
"paging": {
"cursors": {
"before": "ADZZZZ",
"after": "ADZZZZ"
}
}
},
"id": "6054030075149"
}],
"paging": {
"cursors": {
"before": "Juysubgysbyy",
"after": "Nhwunhseuubeyegb"
}
}
}
}]
}
Can anyone help ?
Thanks in Advance !!

First and second data properties have array values, so you should add .[*] after them:
account_name = "$.data.[*].ads.data.[*].insights.data.[*].account_name"
The result:
[
"Emirates WW",
"Emirates WW"
]

Related

Using jq search value using regex

I have this json object and I am trying to find a way to use regex in jq to search value in issuer_dn that is more than 8 characters. A regex like [A-Z]{8} should work but I am unable to get results. I am still learning jq and if there is any other tool that can be used then please share.
{
"ip": "127.0.0.1",
"data": {
"tls": {
"status": "success",
"protocol": "tls",
"result": {
"handshake_log": {
"server_hello": {
"version": {
"name": "TLSv1.2",
"value": 771
},
"random": "hhdshfhhdhfhshdh",
"session_id": "hjdsfyyueujhfjaskdfjjl",
"cipher_suite": {
"hex": "0xC014",
"name": "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
"value": 49172
},
"compression_method": 0,
"ocsp_stapling": false,
"ticket": false,
"secure_renegotiation": true,
"heartbeat": false,
"extended_master_secret": false
},
"server_certificates": {
"certificate": {
"raw": "dGVzdCBkYXRhIGFuZCBnYXJiYWdldGVzdC==",
"parsed": {
"version": 3,
"serial_number": "1234567890",
"signature_algorithm": {
"name": "SHA256-RSA",
"oid": "1.2.840.113549.1.1.11"
},
"issuer": {
"common_name": [
"ABC"
],
"country": [
"ABC"
],
"locality": [
"ABC"
],
"province": [
"ABC"
],
"organization": [
"ABC"
],
"organizational_unit": [
"ABC"
]
},
"issuer_dn": "C=ABCD, ST=ABCD, L=ABCD, O=ABCD, OU=ABCD, CN=ABCD",
"validity": {
"start": "2020-02-01T01:09:22Z",
"end": "2021-02-01T03:09:22Z",
"length": 7883663
},
"subject": {
"common_name": [
"ABC"
],
"country": [
"ABC"
],
"locality": [
"ABC"
],
"province": [
"ABC"
],
"organization": [
"ABC"
],
"organizational_unit": [
"ABC"
]
},
"subject_dn": "C=ABCD, ST=ABCD, L=ABCD, O=ABCD, OU=ABCD, CN=ABCD",
"subject_key_info": {
"key_algorithm": {
"name": "RSA"
},
"rsa_public_key": {
"exponent": 65537,
"modulus": "dGVzdCBkYXRhIGFuZCBnYXJiYWdldGVzdC",
"length": 2048
},
"fingerprint_sha256": "73hh3g39920jfjj38723bb3993hh3774994002"
},
"extensions": {
"basic_constraints": {
"is_ca": true
},
"authority_key_id": "73hh3g39920jfjj38723bb3993hh3774994002",
"subject_key_id": "73hh3g39920jfjj38723bb3993hh3774994002"
},
"signature": {
"signature_algorithm": {
"name": "SHA256-RSA",
"oid": "1.2.840.113549.1.1.11"
},
"value": "dGVzdCBkYXRhIGFuZCBnYXJiYWdldGVzdC",
"valid": true,
"self_signed": true
},
"fingerprint_md5": "73hh3g39920jfjj38723bb3993hh3774994002",
"fingerprint_sha1": "73hh3g39920jfjj38723bb3993hh3774994002",
"fingerprint_sha256": "73hh3g39920jfjj38723bb3993hh3774994002",
"tbs_noct_fingerprint": "73hh3g39920jfjj38723bb3993hh3774994002",
"spki_subject_fingerprint": "73hh3g39920jfjj38723bb3993hh3774994002",
"tbs_fingerprint": "73hh3g39920jfjj38723bb3993hh3774994002",
"validation_level": "73hh3g39920jfjj38723bb3993hh3774994002",
"redacted": false
}
},
"validation": {
"browser_trusted": false,
"browser_error": "x509: failed to load system roots and no roots provided"
}
},
"server_key_exchange": {
"ecdh_params": {
"curve_id": {
"name": "secp256r1",
"id": 23
},
"server_public": {
"x": {
"value": "73hh3g39920jfjj38723bb3993hh3774994002",
"length": 256
},
"y": {
"value": "73hh3g39920jfjj38723bb3993hh3774994002",
"length": 256
}
}
},
"digest": "dGVzdCBkYXRhIGFuZCBnYXJiYWdldGVzdC",
"signature": {
"raw": "dGVzdCBkYXRhIGFuZCBnYXJiYWdldGVzdC",
"type": "rsa",
"valid": true,
"signature_and_hash_type": {
"signature_algorithm": "rsa",
"hash_algorithm": "sha256"
},
"tls_version": {
"name": "TLSv1.2",
"value": 771
}
}
},
"client_key_exchange": {
"ecdh_params": {
"curve_id": {
"name": "secp256r1",
"id": 23
},
"client_public": {
"x": {
"value": "dGVzdCBkYXRhIGFuZCBnYXJiYWdldGVzdC=",
"length": 256
},
"y": {
"value": "dGVzdCBkYXRhIGFuZCBnYXJiYWdldGVzdC=",
"length": 256
}
},
"client_private": {
"value": "dGVzdCBkYXRhIGFuZCBnYXJiYWdldGVzdC=",
"length": 32
}
}
},
"client_finished": {
"verify_data": "dGVzdCBkY"
},
"server_finished": {
"verify_data": "dGVzdCBkY"
},
"key_material": {
"master_secret": {
"value": "dGVzdCBkY",
"length": 48
},
"pre_master_secret": {
"value": "dGVzdCBkY",
"length": 32
}
}
}
},
"timestamp": "2020-02-9T07:14:47Z"
}
}
}
I would use the following :
.data.tls.result.handshake_log.server_certificates.certificate.parsed.issuer_dn \
| select(length > 8)
You can try it here.
You could use:
test("[A-Z]{8}")

Convert json to include name and children values to feed D3

I am trying to get json converted from:
{
"Devices": [
{
"Udid": "7a2b0e6c928f2321a75e423ba23ae93d",
"SerialNumber": "RF1D232ZLEE",
"MacAddress": "40F232726FC8",
"Imei": "3576342323280150",
"EasId": "SEC1BC252327E92B",
"AssetNumber": "7a2b0e23223928f2321a75e423ba23ae93d",
"DeviceFriendlyName": "gel1 Android Android 5.0.1 ZLEE ",
"LocationGroupId": {
"Id": {
"Value": 19529
},
"Name": "Group Express"
},
"LocationGroupName": "Group Express",
"UserId": {
"Name": ""
},
"UserName": "",
"UserEmailAddress": "",
"Ownership": "S",
"PlatformId": {
"Id": {
"Value": 5
},
"Name": "Android"
},
"Platform": "Android",
"ModelId": {
"Id": {
"Value": 5
},
"Name": "samsung GT-I9505"
},
"Model": "samsung GT-I9505",
"OperatingSystem": "5.0.1",
"PhoneNumber": "+447881867010",
"LastSeen": "2016-07-06T14:01:03.590",
"EnrollmentStatus": "Unenrolled",
"ComplianceStatus": "NotAvailable",
"CompromisedStatus": false,
"LastEnrolledOn": "2016-06-15T16:01:38.763",
"LastComplianceCheckOn": "0001-01-01T00:00:00.000",
"LastCompromisedCheckOn": "2016-07-06T13:58:26.183",
"IsSupervised": false,
"DeviceMCC": {
"SIMMCC": "234",
"CurrentMCC": "234"
},
"AcLineStatus": 0,
"VirtualMemory": 0,
"Id": {
"Value": 23459
}
},
{
"Udid": "c5f94db71d406dae7f881d3edf059e",
"SerialNumber": "",
"MacAddress": "000C300F9108",
"Imei": "",
"EasId": "D80DB85EC411C8E9B28BC292A603F05C2C0EEEC8",
"AssetNumber": "c592f93db71d406dae7f881d3edf059e",
"DeviceFriendlyName": "user Windows 10 WinRT 10.0.10240 ",
"LocationGroupId": {
"Id": {
"Value": 18498
},
"Name": "Business Solutions"
},
"LocationGroupName": "Business Solutions",
"UserId": {
"Name": ""
},
"UserName": "",
"UserEmailAddress": "",
"Ownership": "C",
"PlatformId": {
"Id": {
"Value": 12
},
"Name": "WinRT"
},
"Platform": "WinRT",
"ModelId": {
"Id": {
"Value": 50
},
"Name": "Windows 10"
},
"Model": "Windows 10",
"OperatingSystem": "10.0.10240",
"PhoneNumber": "",
"LastSeen": "2016-05-03T10:54:07.650",
"EnrollmentStatus": "Unenrolled",
"ComplianceStatus": "NotAvailable",
"CompromisedStatus": false,
"LastEnrolledOn": "2016-01-29T16:41:57.760",
"LastComplianceCheckOn": "0001-01-01T00:00:00.000",
"LastCompromisedCheckOn": "0001-01-01T00:00:00.000",
"IsSupervised": false,
"DeviceMCC": {
"SIMMCC": "",
"CurrentMCC": ""
},
"AcLineStatus": 0,
"VirtualMemory": 0,
"Id": {
"Value": 23545
}
}
],
"Page": 0,
"PageSize": 500,
"Total": 13}
To something like:
{"name": "Devices",
"children": [
{"name":"Udid", "size":"7f0dsda63274692ea4f0b66fec67a020158"},
{"name":"SerialNumber", "size":"P988KJSPQF938"},
{"name":"MacAddress", "size":"1HJUSUD031C4"},
{"name":"Imei", "size":""},
{"name":"EasId", "size":"ApKJSPQF193"},
{"name":"AssetNumber", "size":"7f0cda636b3305fea4f0b66fec9997267a020158"},
{"name":"DeviceFriendlyName", "size":"TMcKenz iPad iOS 7.1.4 F193 "},
{"name":"LocationGroupId",
"children": [
{"name":"Id","size":7488},
{"name":"Name","size":"MCM"}
]
},
{"name":"UserId",
"children": [
{"name":"Id","size":6418},
{"name":"Name","size":"Tom McKenz"}
]
},
{"name":"UserName", "size":"TMcKenz"},
{"name":"UserEmailAddress", "size":"TMcKenz#awaw.com"}
]
}
Not sure what is the best practice here: is it possible to use D3.nest or do you need to iterate through all the nodes and change to 'name' and 'children' accordingly.

How to get a value of a object from its foreign key?

Im using Backand to store my data. I have an object, Events, that references another object, Locations.
{
"name": "events",
"fields": {
"eventCommentsId": {
"collection": "comments",
"via": "eventId"
},
"tags": {
"collection": "events_tags",
"via": "event"
},
"users": {
"collection": "users_events",
"via": "event"
},
"name": {
"type": "string"
},
"date": {
"type": "datetime"
},
"time": {
"type": "datetime"
},
"info": {
"type": "text"
},
"locationId": {
"object": "locations"
}
},
{
"name": "locations",
"fields": {
"events": {
"collection": "events",
"via": "locationId"
},
"name": {
"type": "text"
},
"geo": {
"type": "point"
}
}
}
When I try to display the location of the event, I can only get the value of locationID. I want the actual name of the location, not the id. How do I do that?
<ion-list>
<ion-item class="item item-thumbnail-left" ng-repeat="event in events" type="item-text-wrap" href="#/event-detail/{{event.id}}">
<h2>{{event.name}}</h2>
<p><i class="ion-location"></i> {{event.locationId.name}}</p>
<ion-option-button class="button-assertive" ng-click="deleteEvent(event.id)">
Delete
</ion-option-button>
</ion-item>
</ion-list>
angular code
.service('EventService', function ($http, Backand) {
var baseUrl = '/1/objects/';
var objectName = 'events/';
function getUrl() {
return Backand.getApiUrl() + baseUrl + objectName;
}
function getUrlForId(id) {
return getUrl() + id;
}
getEvents = function () {
return $http.get(getUrl());
};
addEvent = function(event) {
return $http.post(getUrl(), event);
}
deleteEvent = function (id) {
return $http.delete(getUrlForId(id));
};
getEvent = function (id) {
return $http.get(getUrlForId(id));
};
return {
getEvents: getEvents,
addEvent: addEvent,
deleteEvent: deleteEvent,
getEvent: getEvent
}
})
.controller('FeedCtrl', ['$scope', '$ionicModal', '$ionicSideMenuDelegate', 'EventService', function($scope, $ionicModal, $ionicSideMenuDelegate, EventService) {
$scope.events = [];
$scope.input = {};
function getAllEvents() {
EventService.getEvents()
.then(function (result) {
$scope.events = result.data.data;
});
}
$scope.addEvent = function() {
EventService.addEvent($scope.input)
.then(function(result) {
$scope.input = {};
getAllEvents();
});
}
$scope.deleteEvent = function(id) {
EventService.deleteEvent(id)
.then(function (result) {
getAllEvents();
});
}
getAllEvents();
}])
There are two options. You can either use the descriptive value in the __metadata of each object like this:
request: https://api.backand.com/1/objects/events?pageSize=20&pageNumber=1
response:
{
"totalRows": 2,
"data": [
{
"__metadata": {
"id": "1",
"fields": {
"id": {
"type": "int",
"unique": true
},
"name": {
"type": "string"
},
"date": {
"type": "datetime"
},
"time": {
"type": "datetime"
},
"info": {
"type": "text"
},
"locationId": {
"object": "locations"
}
},
"descriptives": {
"locationId": {
"label": "Madison Square Garden",
"value": "1"
}
},
"dates": {
"date": "",
"time": ""
}
},
"id": 1,
"name": "knicks vs warriors",
"date": null,
"time": null,
"info": "",
"locationId": "1"
},
{
"__metadata": {
"id": "2",
"fields": {
"id": {
"type": "int",
"unique": true
},
"name": {
"type": "string"
},
"date": {
"type": "datetime"
},
"time": {
"type": "datetime"
},
"info": {
"type": "text"
},
"locationId": {
"object": "locations"
}
},
"descriptives": {
"locationId": {
"label": "Madison Square Garden",
"value": "1"
}
},
"dates": {
"date": "",
"time": ""
}
},
"id": 2,
"name": "knicks vs cavs",
"date": null,
"time": null,
"info": "",
"locationId": "1"
}
]
}
or you can do a deep request and get the value in the relatedObjects
request: https://api.backand.com/1/objects/events?pageSize=20&pageNumber=1&deep=true
response:
{
"totalRows": 2,
"data": [
{
"__metadata": {
"id": "1",
"fields": {
"id": {
"type": "int",
"unique": true
},
"name": {
"type": "string"
},
"date": {
"type": "datetime"
},
"time": {
"type": "datetime"
},
"info": {
"type": "text"
},
"locationId": {
"object": "locations"
}
},
"descriptives": {
"locationId": {
"label": "Madison Square Garden",
"value": "1"
}
},
"dates": {
"date": "",
"time": ""
}
},
"id": 1,
"name": "knicks vs warriors",
"date": null,
"time": null,
"info": "",
"locationId": "1"
},
{
"__metadata": {
"id": "2",
"fields": {
"id": {
"type": "int",
"unique": true
},
"name": {
"type": "string"
},
"date": {
"type": "datetime"
},
"time": {
"type": "datetime"
},
"info": {
"type": "text"
},
"locationId": {
"object": "locations"
}
},
"descriptives": {
"locationId": {
"label": "Madison Square Garden",
"value": "1"
}
},
"dates": {
"date": "",
"time": ""
}
},
"id": 2,
"name": "knicks vs cavs",
"date": null,
"time": null,
"info": "",
"locationId": "1"
}
],
"relatedObjects": {
"locations": {
"1": {
"__metadata": {
"id": "1",
"fields": {
"id": {
"type": "int",
"unique": true
},
"events": {
"collection": "events",
"via": "locationId"
},
"name": {
"type": "text"
},
"geo": {
"type": "point"
}
},
"descriptives": {},
"dates": {}
},
"id": 1,
"events": null,
"name": "Madison Square Garden",
"geo": [
40.7505,
73.9934
]
}
}
}
}
search for Madison Square Garden as the name of the location to understand the JSON structure.
You can set the descriptive field in the Object Settings

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.

Bookshelf.js FindOrCreate method

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.