JSON Array Parse Error - arrays

JSON editor shows error on line 5. But is not everything okay for my JSON?
My JSON file:
{
"status": "ok",
"errorMessage": "",
"result": [
"data_x": [{
"date": "2018-03-09T05:17:08",
"value": 12.00
}],
"data_y": [{
"date": "2018-03-09T05:17:08",
"value": 36.50
}],
"data_z": [{
"date": "2018-03-09T05:17:08",
"value": 88.50
}]
]
}
Thanks.

Missing curly brackets in result array.
It should be like below:
{
"status": "ok",
"errorMessage": "",
"result": [{
"data_x": [{
"date": "2018-03-09T05:17:08",
"value": 12.00
}],
"data_y": [{
"date": "2018-03-09T05:17:08",
"value": 36.50
}],
"data_z": [{
"date": "2018-03-09T05:17:08",
"value": 88.50
}]
}]
}
Validated on jsonlint

"result" is an array ([]) and you are defining properties within as if it was an object ({}).
You may want to make it an object:
{
"status":"ok",
"errorMessage":"",
"result":{
"data_x":[
{
"date":"2018-03-09T05:17:08",
"value":12.00
}
],
"data_y":[
{
"date":"2018-03-09T05:17:08",
"value":36.50
}
],
"data_z":[
{
"date":"2018-03-09T05:17:08",
"value":88.50
}
]
}
}
Or, if you want to keep the array, you can do as imEnCoded says:
{
"status": "ok",
"errorMessage": "",
"result": [{
"data_x": [{
"date": "2018-03-09T05:17:08",
"value": 12.00
}],
"data_y": [{
"date": "2018-03-09T05:17:08",
"value": 36.50
}],
"data_z": [{
"date": "2018-03-09T05:17:08",
"value": 88.50
}]
}]
}

Related

angular js fetching data from url

I am new to angular js.I am trying to fetch data from url.I know how to fetch data from json with single array.But if the json has many arrays,then how to fetch it?
For example:
The json is as follows:
{
"Details": [{
"approved": [{
"count": "2124",
"type": "Approved ",
"desc": "New registration"
}, {
"count": "902",
"type": "Deemed approved ",
"desc": "New registration"
}, {
"count": "60",
"type": "Approved ",
"desc": null
}, {
"count": "5",
"type": "Deemed approved ",
"desc": null
}, {
"count": "29",
"type": "Approved ",
"desc": null
}]
}, {
"pending": [{
"count": "492",
"type": "Amendment of core fields"
}, {
"count": "18",
"type": "New registration"
}, {
"count": "1",
"type": null
}]
}, {
"rejected": [{
"count": "29",
"type": "New registration"
}]
}, {
"resubmit": [{
"count": "9",
"type": "New registration"
}]
}]
}
Lets say you send the request as follows:
$http.get('/data').then(function(response) {
response // your JSON
});
Now inside response you will have your entire JSON as a javascript object. So you can use it as follows:
response.Details.approved[0].count // 2124
response.Details.pending[0].count // 492

DataTables - Load data from pre-defined JSON

I have a problem pointing dataTable to the right spot in the JSON. I receive a nested array:
{
"status": "ok",
"count": "7",
"msg ": "Operation Successful",
"data": [{
"contactHasServiceArea": true,
"issueCategories": [{
"id": "8",
"description": "Finance"
},
{
"id": "9",
"description": "Housing"
},
{
"id": "10",
"description": "International"
}
],
"cases": [{
"id": 31645,
"client_name": "Matthew",
"issue": "Assessment Completion",
"referral": null,
"opened_date": "10\/07\/2017",
"case_status": "Open"
}, {
"id": 31668,
"client_name": "Fanky ",
"issue": "Complex",
"referral": null,
"opened_date": "01\/07\/2017",
"case_status": "Open"
}]
}]
}
How do I point to the "cases" object? I'm sure this is simply, but I'm confused by the many options in the dataTables config.
I tried variations of data, dataSrc as well as data.cases or just cases, etc.
Thanks
$('#cases_table').DataTable( {
"ajax": "ajax/getCases",
"dataSrc" : "data.cases",
"data" : "cases",
"columns": [
{ "data": "client_name" },
{ "data": "issue" },
{ "data": "referral" },
{ "data": "opened_date" },
{ "data": "case_status" }
]
} );
You can configure like this:
$('#cases_table').DataTable( {
"ajax": {
"url": "ajax/getCases",
"dataSrc" : "data.cases"
},
"columns": [
{ "data": "client_name" },
{ "data": "issue" },
{ "data": "referral" },
{ "data": "opened_date" },
{ "data": "case_status" }
]
} );
datasrc points into the returns json. Remove the data option.

Multi-dimensional arrays in Mandrill with handlebars

I'm trying to loop through a multi-dimensional array to get properties of products that are part of line items. They look basically like this: (I did a json_encode so it would be easier to read)
[{
"rcpt": "email#email.com",
"vars": [{
"name": "SYSTEM",
"content": "Bikes"
}, {
"name": "CUSTOMERSERVICE",
"content": "(855-553-4889)"
}, {
"name": "IMAGE",
"content": "http:\/\/www.url.com\/assets\/images\/chicago\/email\/dear_member.jpg"
}, {
"name": "LINKCOLOR",
"content": "#3db7e4"
}, {
"name": "FACEBOOK",
"content": "Bikes"
}, {
"name": "TWITTER",
"content": "Bikes"
}, {
"name": "INSTAGRAM",
"content": "Bikes"
}, {
"name": "CLOSING",
"content": "Greetings"
}, {
"name": "item",
"content": [{
"lineItem": 1,
"id": "3",
"name": "24-Hour Pass Gift Certificate",
"quantity": 2,
"nameShort": "24-Hour",
"type": "Gift Certificate",
"image": "24hour_blank.jpg",
"price": "9.95",
"total": "19.90",
"taxable": false,
"giftCertificates": {
"3204": {
"id": "3204",
"redemptionNumber": "xxxxx",
"type": "24-Hour"
},
"3205": {
"id": "3205",
"redemptionNumber": "xxxxx",
"type": "24-Hour"
}
}
}, {
"lineItem": 2,
"id": "1",
"name": "Annual Membership Gift Certificate",
"quantity": 2,
"nameShort": "Annual",
"type": "Gift Certificate",
"image": "annual_blank.jpg",
"price": "75.00",
"total": "150.00",
"taxable": false,
"giftCertificates": {
"892": {
"id": "892",
"redemptionNumber": "xxxxxx",
"type": "Annual"
},
"893": {
"id": "893",
"redemptionNumber": "xxxxx",
"type": "Annual"
}
}
}]
}, {
"name": "orderID",
"content": 1220
}, {
"name": "giftMessage",
"content": false
}, {
"name": "email",
"content": "email#email.com"
}, {
"name": "transactionDate",
"content": "12\/23\/2015"
}, {
"name": "transactionTime",
"content": "12:21 pm"
}, {
"name": "salesTaxTotal",
"content": 0
}, {
"name": "salesTaxRatePercent",
"content": "6.250"
}, {
"name": "TransactionAmount",
"content": "169.90"
}, {
"name": "account_number",
"content": "XXXX1111"
}, {
"name": "card_type",
"content": "Visa"
}, {
"name": "firstName",
"content": "tetete"
}, {
"name": "lastName",
"content": "tethuhhu"
}, {
"name": "address",
"content": "295 Place St"
}, {
"name": "city",
"content": "Brooklyn"
}, {
"name": "state",
"content": "NY"
}, {
"name": "zip",
"content": "11238"
}, {
"name": "country",
"content": "US"
}, {
"name": "phone",
"content": "8888888888"
}, {
"name": "transactionId",
"content": "xxxxxx"
}, {
"name": "shipToFirstName",
"content": "tetete"
}, {
"name": "shipToLastName",
"content": "tethuhhu"
}, {
"name": "shipToAaddress",
"content": "295 Place St"
}, {
"name": "shipToCity",
"content": "Brooklyn"
}, {
"name": "shipToState",
"content": "NY"
}, {
"name": "shipToZipCode",
"content": "11238"
}, {
"name": "ShipToCountry",
"content": "US"
}, {
"name": "ShipToCountry",
"content": "US"
}]
}]
So I am trying to get a print out of each gift certificate's type and redemption number. When I iterate through {{ giftCertificates }} like this:
{{#each giftCertificates}}
{{type}} {{redemptionNumber}}
{{/each}}
I get one of the line items but not the other. I'm guessing maybe it is being overwritten when it loops through again? But I have also tried to loop through {{ item }} and grab {{ giftCertificates.type }} and {{ giftCertificates.redemptionNumber }} and that does not work either. What is the correct way to get all of these from each line item?
Thanks for your help.
I know this is a very old question, but:
you can use {{this.proprietyName}} to get the type and number:
{{#each giftCertificates}}
{{this.892.type}}
{{/each}}
do not forget to add this to the mandrill message o
"merge": true,
"merge_language": "handlebars",
Also, the data structure is not ideal:
giftCertificates[
{
"id": "892",
"redemptionNumber": "xxxxxx",
"type": "Annual"
},
{
"id": "893",
"redemptionNumber": "xxxxxx",
"type": "Annual"
}
]
would be easier to handle.

AngularJS access JSON index values dynamically

My scope data:
$scope.data =
"category": [{
"name": "cat1",
"behaviour": "normal",
"selected": 0,
"values": [{
"label": "define",
"count": 6
}]
}, {
"name": "cat2",
"behaviour": "normal",
"selected": 0,
"values": [{
"label": "type",
"count": 6
}]
}, {
"name": "Company",
"behaviour": "multi-select",
"selected": 0,
"values": [{
"label": "VW",
"count": 4
}, {
"label": "Renault",
"count": 1
}, {
"label": "Fiat",
"count": 1
}]
}, {
"name": "Make",
"behaviour": "multi-select",
"selected": 0,
"values": [{
"label": "Gold",
"count": 3
}]
}, {
"name": "Color",
"behaviour": "normal",
"selected": 0,
"values": [{
"label": "White",
"count": 3
}, {
"label": "Blue",
"count": 2
}, {
"label": "Green",
"count": 1
}]
}]
How can I access the "name":"value" without using indexes? as the data might grow and change and I don't want to assign an index value anywhere? I'd still want to filter such as:
| {name: 'Make'}: true)
in my mark up to show
So the json is incorrect, i corrected it (next time you can use this site to see if your json is valid JSONVALIDATOR)
If you want to access at value of the name do this
In your controller :
$scope.data = [
{
"name": "cat1",
"behaviour": "normal",
"selected": 0,
"values": [
{
"label": "define",
"count": 6
}
]
},
{
"name": "cat2",
"behaviour": "normal",
"selected": 0,
"values": [
{
"label": "type",
"count": 6
}
]
},
{
"name": "Company",
"behaviour": "multi-select",
"selected": 0,
"values": [
{
"label": "VW",
"count": 4
},
{
"label": "Renault",
"count": 1
},
{
"label": "Fiat",
"count": 1
}
]
},
{
"name": "Make",
"behaviour": "multi-select",
"selected": 0,
"values": [
{
"label": "Gold",
"count": 3
}
]
},
{
"name": "Color",
"behaviour": "normal",
"selected": 0,
"values": [
{
"label": "White",
"count": 3
},
{
"label": "Blue",
"count": 2
},
{
"label": "Green",
"count": 1
}
]
}
];
In your HTML
<div ng-repeat="d in data"> {{d.name}} </div>
If you want to display values of the object with the name 'Company' you can do this like in my working CodePen :
Just add a new ng-repeat :
<div ng-repeat="d in data"> {{d.name}}
<div ng-if="d.name == 'Company'" ng-repeat="da in d.values">{{da.label}}</div>
</div>
First off, the format of your data is not correct JSON format, run it through an online validator.
To access the element, you would simply be able to through:
<li ng-repeat="item in data">
{{ item.name }} {{ item.behaviour }} etc...
</li>
Get rid of category within $scope.data... just let it be an array like a typical JSON value.

Json reader rootProperty call in sencha touch store

{
"success": true,
"message": "Successfully retrieved data for report #1",
"content": {
"fields": ["name", "2013", "2012", "2011"],
"data": [{
"name": "1",
"2011": 378.4,
"2012": 208.95,
"2013": 229.92
}, {
"name": "2",
"2011": 258.92,
"2013": 265.92
}, {
"name": "3",
"2011": 242,
"2012": 227.98,
"2013": 558.13
}, {
"name": "4",
"2011": 322.5,
"2012": 390,
"2013": 282.09
}, {
"name": "5",
"2011": 563.88,
"2013": 461.1
}, {
"name": "7",
"2011": 268.5,
"2012": 305.48
}]
}
}
this is my json .. I want to read data:[{name:"",..... }] from my store,so I am giving rootProperty: content[0].data but it is not working, can anyone please tell me how to read that data and help me on this issue. Thank you .
Found it rootProperty: 'content.data' working fine.My issue is with url . Thank you

Resources