How to count number of lines containing a string in an API? - javascript
I'm looking to count the number of times a crime has occurred on a street by counting the times the street is mentioned in a police statistics site then display it.
The display bit I can do, rather it's pulling the count into a variable that I'm struggling to understand where to start.
The data is: https://data.police.uk/api/crimes-street/all-crime?lat=51.728395&lng=-1.2314066
Here's an example of doing it:
fetch(
"https://data.police.uk/api/crimes-street/all-crime?lat=51.728395&lng=-1.2314066"
).then(async (data) => {
const records = await data.json();
// If you'd like to filter records for streets with specific name
const filterByStreetName = (streetName, records) => {
return records.reduce(function (filtered, record) {
if (record.location.street.name.includes(streetName)) {
filtered.push(record);
}
return filtered;
}, []);
};
const elmTreeStreetRecords = filterByStreetName("Elm Tree", records);
console.log(elmTreeStreets);
// Get all street names
const allStreets = records.map((x) => x.location.street.name);
// if you would prefer using ids instead of street names (probably better idea), just change used object property
// const allStreets = records.map((x) => x.location.street.id);
// // Use reduce to create object with street name and count in format streetName:Count
const streetsWithCount = allStreets.reduce((accumulator, value) => {
return { ...accumulator, [value]: (accumulator[value] || 0) + 1 };
}, {});
// if you need to sort them
const sortableStreetNames = Object.entries(streetsWithCount);
const sortedStreetsByCountInDescendingOrder = sortableStreetNames.sort(
([, a], [, b]) => b - a
);
console.log("streetsWithCount", streetsWithCount);
// => {On or near Elm Tree Close: 5, On or near Champion Way: 2}
console.log("allStreets", allStreets);
// => ["On or near Elm Tree Close", "On or near Sports/recreation Area", "On or near Champion Way", "On or near Oxford Road", "On or near Parking Area", "On or near Pedestrian Subway", "On or near Newman Road", "On or near Constance Norman Way", "On or near Catherine Street", "On or near Littlehay Road", …]
console.log("sortedStreetsByCount", sortedStreetsByCountInDescendingOrder);
// => [["On or near Parking Area", 49], ["On or near Supermarket", 29]]
});
It is a pure data from an API, which is not ideal "on or near Parking Area", you didn't specify format, but it is a good place to start, maybe API has some better querying options, maybe you could just filter out some results, or format returned results in a way you want to display them.
You can use Array#reduce to count the occurences given the street ID:
// return a promise to simplify everything
async function streetCount(streetId) {
let response = await fetch("https://data.police.uk/api/crimes-street/all-crime?lat=51.728395&lng=-1.2314066");
let data = await response.json();
// create a counter
return data.reduce((prev, cur) =>
prev + +(cur?.location?.street?.id === streetId), 0); // add the previous count to whether the street ID matches the provided one
// we cast the boolean to a number, so if it's true it'll give 1 (add 1 to the counter) and otherwise 0
// optional chaining is used in case the API provides malformed data; code will still work if removed
}
streetCount(1203542).then(count => {
console.log("Crime occurences:", count);
});
that's it, folks
const allCrimes = [{
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.723879", "street": { "id": 1203542, "name": "On or near Elm Tree Close" }, "longitude": "-1.221349" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102646934, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.725988", "street": { "id": 1203518, "name": "On or near Sports\/recreation Area" }, "longitude": "-1.211410" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647063, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.723362", "street": { "id": 1203546, "name": "On or near Champion Way" }, "longitude": "-1.219389" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102646887, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.725683", "street": { "id": 1203528, "name": "On or near Oxford Road" }, "longitude": "-1.223634" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647032, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.733223", "street": { "id": 1204183, "name": "On or near Parking Area" }, "longitude": "-1.217713" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647491, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.724270", "street": { "id": 1203378, "name": "On or near Pedestrian Subway" }, "longitude": "-1.224730" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647022, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.725454", "street": { "id": 1203529, "name": "On or near Newman Road" }, "longitude": "-1.221684" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647008, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.724505", "street": { "id": 1203430, "name": "On or near Constance Norman Way" }, "longitude": "-1.231762" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647006, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.741460", "street": { "id": 1204314, "name": "On or near Catherine Street" }, "longitude": "-1.232879" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647957, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.736008", "street": { "id": 1204151, "name": "On or near Littlehay Road" }, "longitude": "-1.220069" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647691, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.735840", "street": { "id": 1204256, "name": "On or near Weirs Lane" }, "longitude": "-1.241070" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647682, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.730241", "street": { "id": 1204163, "name": "On or near The Grates" }, "longitude": "-1.216823" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647298, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.733223", "street": { "id": 1204183, "name": "On or near Parking Area" }, "longitude": "-1.217713" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647489, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.733223", "street": { "id": 1204183, "name": "On or near Parking Area" }, "longitude": "-1.217713" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647488, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.728327", "street": { "id": 1203508, "name": "On or near Bartholomew Road" }, "longitude": "-1.214294" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647262, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.734466", "street": { "id": 1204251, "name": "On or near Police Station" }, "longitude": "-1.213898" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647566, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.723879", "street": { "id": 1203542, "name": "On or near Elm Tree Close" }, "longitude": "-1.221349" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102646925, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.737846", "street": { "id": 1204282, "name": "On or near Swinburne Road" }, "longitude": "-1.238342" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647752, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.737395", "street": { "id": 1204202, "name": "On or near Owens Way" }, "longitude": "-1.216236" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647776, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.726360", "street": { "id": 1203426, "name": "On or near Court Place Gardens" }, "longitude": "-1.237783" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647072, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.722292", "street": { "id": 1203460, "name": "On or near Spring Lane" }, "longitude": "-1.211242" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102646796, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.734236", "street": { "id": 1204200, "name": "On or near Oxford Road" }, "longitude": "-1.211889" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647589, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.731954", "street": { "id": 1204211, "name": "On or near Knolles Road" }, "longitude": "-1.213463" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647367, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.727149", "street": { "id": 1203509, "name": "On or near Barns Road" }, "longitude": "-1.210275" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647146, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.726360", "street": { "id": 1203426, "name": "On or near Court Place Gardens" }, "longitude": "-1.237783" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647070, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.719306", "street": { "id": 1203470, "name": "On or near Priory Road" }, "longitude": "-1.215246" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102646560, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.724426", "street": { "id": 1203436, "name": "On or near Asquith Road" }, "longitude": "-1.226653" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102646945, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.727149", "street": { "id": 1203509, "name": "On or near Barns Road" }, "longitude": "-1.210275" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647143, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.727149", "street": { "id": 1203509, "name": "On or near Barns Road" }, "longitude": "-1.210275" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647142, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.732969", "street": { "id": 1204378, "name": "On or near Sports\/recreation Area" }, "longitude": "-1.250385" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647439, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.732987", "street": { "id": 1204240, "name": "On or near Petrol Station" }, "longitude": "-1.214676" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647449, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.731954", "street": { "id": 1204211, "name": "On or near Knolles Road" }, "longitude": "-1.213463" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647353, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.738885", "street": { "id": 1204288, "name": "On or near Quartermain Close" }, "longitude": "-1.233618" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647855, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.730911", "street": { "id": 1204272, "name": "On or near Egerton Road" }, "longitude": "-1.228367" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647349, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.732987", "street": { "id": 1204240, "name": "On or near Petrol Station" }, "longitude": "-1.214676" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647526, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.737124", "street": { "id": 1204153, "name": "On or near Hendred Street" }, "longitude": "-1.220151" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647743, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.730387", "street": { "id": 1204176, "name": "On or near Boswell Road" }, "longitude": "-1.211637" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647347, "location_subtype": "", "month": "2022-06"
}, {
"category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.729723", "street": { "id": 1204166, "name": "On or near Littlemore Road" }, "longitude": "-1.218715" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 102647291, "location_subtype": "", "month": "2022-06"
}, {
"category": "bicycle-theft", "location_type": "Force", "location": { "latitude": "51.724779", "street": { "id": 1203481, "name": "On or near Long Lane" }, "longitude": "-1.217453" }, "context": "", "outcome_status": {
"category": "Under investigation", "date": "2022-06"
}, "persistent_id": "3db491eb02f57648df9a2af8f1132772ec6bb8f2def3f947747bf22e65885e2b", "id": 102646899, "location_subtype": "", "month": "2022-06"
}, {
"category": "bicycle-theft", "location_type": "Force", "location": { "latitude": "51.732294", "street": { "id": 1204236, "name": "On or near Banjo Road" }, "longitude": "-1.217150" }, "context": "", "outcome_status": {
"category": "Investigation complete; no suspect identified", "date": "2022-06"
}, "persistent_id": "f254759e21c52428736f04bbac13b4a1ef1652e593c55e8c26499c1e57532b8a", "id": 102647441, "location_subtype": "", "month": "2022-06"
}, {
"category": "bicycle-theft", "location_type": "Force", "location": { "latitude": "51.740796", "street": { "id": 1204143, "name": "On or near Weyman Terrace" }, "longitude": "-1.222000" }, "context": "", "outcome_status": {
"category": "Investigation complete; no suspect identified", "date": "2022-06"
}, "persistent_id": "93c63312fb6b04b1f5c2147f0957f90506db1efdf911cc4dd0dedb1ba779c1c7", "id": 102647926, "location_subtype": "", "month": "2022-06"
}, {
"category": "bicycle-theft", "location_type": "Force", "location": { "latitude": "51.737804", "street": { "id": 1204239, "name": "On or near Agnes Court" }, "longitude": "-1.218271" }, "context": "", "outcome_status": {
"category": "Investigation complete; no suspect identified", "date": "2022-06"
}, "persistent_id": "6da017672b1e62fdd1e9fe7a3c8f8290554cb1c2197f1d5a32ec3370a2c64b7b", "id": 102647784, "location_subtype": "", "month": "2022-06"
}, {
"category": "bicycle-theft", "location_type": "Force", "location": { "latitude": "51.735523", "street": { "id": 1204199, "name": "On or near Oxford Road" }, "longitude": "-1.215965" }, "context": "", "outcome_status": {
"category": "Investigation complete; no suspect identified", "date": "2022-06"
}, "persistent_id": "b8087f61f3ee54a434603fd413351c3786696945f8311ab8fe66c1b3ce1f309b", "id": 102647657, "location_subtype": "", "month": "2022-06"
}, {
"category": "bicycle-theft", "location_type": "Force", "location": { "latitude": "51.735840", "street": { "id": 1204256, "name": "On or near Weirs Lane" }, "longitude": "-1.241070" }, "context": "", "outcome_status": {
"category": "Investigation complete; no suspect identified", "date": "2022-06"
}, "persistent_id": "81eb687f2a3e6f7c4bc33e23ba532dc8012ea08594a286a00d45935909dfb9ff", "id": 102647655, "location_subtype": "", "month": "2022-06"
}, {
"category": "bicycle-theft", "location_type": "Force", "location": { "latitude": "51.736008", "street": { "id": 1204151, "name": "On or near Littlehay Road" }, "longitude": "-1.220069" }, "context": "", "outcome_status": {
"category": "Investigation complete; no suspect identified", "date": "2022-06"
}, "persistent_id": "4d82424f72981ac1e5e3c9c77d054aa533bc1a96e8239894e3a387d1941327ce", "id": 102647644, "location_subtype": "", "month": "2022-06"
}, {
"category": "bicycle-theft", "location_type": "Force", "location": { "latitude": "51.734466", "street": { "id": 1204251, "name": "On or near Police Station" }, "longitude": "-1.213898" }, "context": "", "outcome_status": {
"category": "Under investigation", "date": "2022-06"
}, "persistent_id": "823cc48203d0ee98a4c3804fbb800f38a1b52f6a0812699860cfc5a273478fe9", "id": 102647619, "location_subtype": "", "month": "2022-06"
}, {
"category": "bicycle-theft", "location_type": "Force", "location": { "latitude": "51.734902", "street": { "id": 1204235, "name": "On or near Bennett Crescent" }, "longitude": "-1.210617" }, "context": "", "outcome_status": {
"category": "Investigation complete; no suspect identified", "date": "2022-06"
}, "persistent_id": "9272b4253caac3c49771bab03aa16ac377fc257b266f2624caa4979f20175973", "id": 102647599, "location_subtype": "", "month": "2022-06"
}, {
"category": "bicycle-theft", "location_type": "Force", "location": { "latitude": "51.734236", "street": { "id": 1204200, "name": "On or near Oxford Road" }, "longitude": "-1.211889" }, "context": "", "outcome_status": {
"category": "Unable to prosecute suspect", "date": "2022-06"
}, "persistent_id": "d821df571e79d0ee6c1655a57aebab9cec661651812b8e33ed0b7b729283735a", "id": 102647562, "location_subtype": "", "month": "2022-06"
}, {
"category": "bicycle-theft", "location_type": "Force", "location": { "latitude": "51.733850", "street": { "id": 1204221, "name": "On or near Gerard Place" }, "longitude": "-1.214632" }, "context": "", "outcome_status": {
"category": "Investigation complete; no suspect identified", "date": "2022-06"
}, "persistent_id": "08b1894f4389bfe50ccb19e1211b37a35bb201038f3e8de6f1ccff2ff651ab46", "id": 102647549, "location_subtype": "", "month": "2022-06"
}, {
"category": "bicycle-theft", "location_type": "Force", "location": { "latitude": "51.732987", "street": { "id": 1204240, "name": "On or near Petrol Station" }, "longitude": "-1.214676" }, "context": "", "outcome_status": {
"category": "Investigation complete; no suspect identified", "date": "2022-06"
}, "persistent_id": "350b18d189f77795e44f6881c2a1d7758c6756c2a0e1bb692d823cff882b0458", "id": 102647525, "location_subtype": "", "month": "2022-06"
}, {
"category": "bicycle-theft", "location_type": "Force", "location": { "latitude": "51.733223", "street": { "id": 1204183, "name": "On or near Parking Area" }, "longitude": "-1.217713" }, "context": "", "outcome_status": {
"category": "Investigation complete; no suspect identified", "date": "2022-06"
}, "persistent_id": "45b956b4552c06ac28c56cb10ba56b13515e97fff894a9072f548469117091ab", "id": 102647520, "location_subtype": "", "month": "2022-06"
}];
/* crimes at specific street */
function getAmountOfCrimesAtStreetId(streetId) {
const crimesAtStreetId = allCrimes.filter(crimeData => crimeData.location.street.id === streetId);
return crimesAtStreetId.length;
}
const amountOfCrimesAtStreet_1204183 = getAmountOfCrimesAtStreetId(1204183);
console.log(amountOfCrimesAtStreet_1204183); // 4
/* crimes on each street */
// get all unique street ids
const allUniqueStreetIds = [...new Set(allCrimes.map(crimeData=>crimeData.location.street.id))];
// create an object to store amounts of crimes on each street
const amountOfCrimesAtStreet = {};
allUniqueStreetIds.forEach(streetId=>{
const streetIdString = String(streetId);
amountOfCrimesAtStreet[streetIdString] = 0;
});
// fill this object with amounts of crimes (incrementing inside the loop)
allCrimes.forEach(crimeData=>{
const streetIdString = String(crimeData.location.street.id);
amountOfCrimesAtStreet[streetIdString]+=1;
});
// the same result
console.log(amountOfCrimesAtStreet["1204183"]); // 4
Related
response.map() is not a function in reactjs
Hi I am calling an API using axios. it is returning data. that data I am using to populate a table. but it is giving error. const [response, setResponse] = useState([]); const [flag, setFlag] = useState(false); await axios.get(`http://localhost:3000/api/certificates?page=${page}`,{ params: param, }).then(res=>{ console.log(res.data); setResponse(res.data); setFlag(true); }) then I am using response into table to populate data. table will be populated only if flag become true. <div className="col-md-10 container"> { flag && ( <table className="table table-bordered "> <tbody> { flag && response.map((certificate: Certificate, index: number) => ( <tr> <td>{certificate.certifcateNo}</td> <td>{certificate.protoCOlNo}</td> </tr> } </tbody> </table> </div> My API is returning below output from postman { "data": [ { "id": "cace4b0c-2836-412a-be60-78f726917ff6", "createdAt": "2021-12-03T21:06:14.540Z", "modifiedAt": "2021-12-03T21:06:14.540Z", "deletedAt": null, "certificateNo": 1, "requestStatus": "DRAFT", "sponser": "Onkar", "address": "JBP", "address2": "BUSINESS BAY", "zipCode": "40013", "city": "MH", "protoColNo": "123", "molecules": "Shweta", "unAuthMolecule": "NO", "phaseOfTrial": 1, "noOfSubjects": "5", "startDate": "2011-11-09", "endDate": "2012-11-09", "personInCharge": "Deepali", "country": "India", "comments": "I am Genius", "attachedFile": "string" }, { "id": "91dfa4e3-d7f7-4671-b3e3-ba90c6454a1a", "createdAt": "2021-12-03T21:06:22.690Z", "modifiedAt": "2021-12-03T21:06:22.690Z", "deletedAt": null, "certificateNo": 2, "requestStatus": "DRAFT", "sponser": "Onkar", "address": "JBP", "address2": "BUSINESS BAY", "zipCode": "40013", "city": "MH", "protoColNo": "123", "molecules": "Shweta", "unAuthMolecule": "NO", "phaseOfTrial": 1, "noOfSubjects": "5", "startDate": "2011-11-09", "endDate": "2012-11-09", "personInCharge": "Deepali", "country": "India", "comments": "I am Genius", "attachedFile": "string" }, { "id": "c84d7bce-cdcb-4984-89a2-ad2291651867", "createdAt": "2021-12-03T21:06:23.398Z", "modifiedAt": "2021-12-03T21:06:23.398Z", "deletedAt": null, "certificateNo": 3, "requestStatus": "DRAFT", "sponser": "Onkar", "address": "JBP", "address2": "BUSINESS BAY", "zipCode": "40013", "city": "MH", "protoColNo": "123", "molecules": "Shweta", "unAuthMolecule": "NO", "phaseOfTrial": 1, "noOfSubjects": "5", "startDate": "2011-11-09", "endDate": "2012-11-09", "personInCharge": "Deepali", "country": "India", "comments": "I am Genius", "attachedFile": "string" }, { "id": "0755d2f9-50df-4b5a-a863-d173a12b45b5", "createdAt": "2021-12-03T21:06:23.762Z", "modifiedAt": "2021-12-03T21:06:23.762Z", "deletedAt": null, "certificateNo": 4, "requestStatus": "DRAFT", "sponser": "Onkar", "address": "JBP", "address2": "BUSINESS BAY", "zipCode": "40013", "city": "MH", "protoColNo": "123", "molecules": "Shweta", "unAuthMolecule": "NO", "phaseOfTrial": 1, "noOfSubjects": "5", "startDate": "2011-11-09", "endDate": "2012-11-09", "personInCharge": "Deepali", "country": "India", "comments": "I am Genius", "attachedFile": "string" }, { "id": "05c1ce23-eaf6-4ff9-aa5c-5f0554a22205", "createdAt": "2021-12-03T21:06:24.032Z", "modifiedAt": "2021-12-03T21:06:24.032Z", "deletedAt": null, "certificateNo": 5, "requestStatus": "DRAFT", "sponser": "Onkar", "address": "JBP", "address2": "BUSINESS BAY", "zipCode": "40013", "city": "MH", "protoColNo": "123", "molecules": "Shweta", "unAuthMolecule": "NO", "phaseOfTrial": 1, "noOfSubjects": "5", "startDate": "2011-11-09", "endDate": "2012-11-09", "personInCharge": "Deepali", "country": "India", "comments": "I am Genius", "attachedFile": "string" } ], "meta": { "total": 16, "page": "1", "last_page": 4 } } what mistake I am doing?
Idk if you just wrote your code too quickly, but you are missing closing parentheses. { flag && response.map((certificate: Certificate, index: number) => ( <tr> <td>{certificate.certifcateNo}</td> <td>{certificate.protoCOlNo}</td> </tr> ))} <-- here
const {data} = await axios.get(`http://localhost:3000/api/certificates?page=${page}`,{ params: param, }) console.log(data.data); setResponse(data.data); setFlag(true);
Microsoft Graph Api - Appointment Bookings dateTime Issue
So i've been using the microsoft bookings Beta Api getting the List from this URL: GET https://graph.microsoft.com/beta/bookingBusinesses/Contosolunchdelivery#M365B489948.onmicrosoft.com/appointments it works fine except i need to get the start -> dateTime and end -> dateTime for the specific appointment but its returning wrong start dates? even though when i go to bookings i clearly put the start time. This is what the JSON-Example should looks like: { "#odata.context": "https://graph.microsoft.com/beta/$metadata#bookingBusinesses('Contosolunchdelivery%40M365B489948.onmicrosoft.com')/appointments", "value": [ { "id": "AAMkADKoAAA=", "selfServiceAppointmentId": "00000000-0000-0000-0000-000000000000", "customerId": "829e3cb5-3d4d-4319-a8de-1953aedaa166", "customerName": "Bob Kelly", "customerEmailAddress": "bobk#tailspintoys.com", "customerPhone": "213-555-0108", "customerNotes": null, "serviceId": "57da6774-a087-4d69-b0e6-6fb82c339976", "serviceName": "Catered bento", "duration": "PT30M", "preBuffer": "PT5M", "postBuffer": "PT10M", "priceType": "fixedPrice", "price": 10, "serviceNotes": null, "optOutOfCustomerEmail": false, "staffMemberIds": [], "invoiceAmount": 10, "invoiceId": "1002", "invoiceStatus": "open", "invoiceUrl": "theInvoiceUrl", "customerLocation": { "displayName": "Customer", "locationEmailAddress": null, "locationUri": "", "locationType": null, "uniqueId": null, "uniqueIdType": null, "address": { "type": "home", "postOfficeBox": "", "street": "", "city": "", "state": "", "countryOrRegion": "", "postalCode": "" }, "coordinates": { "altitude": null, "latitude": null, "longitude": null, "accuracy": null, "altitudeAccuracy": null } }, "start": { "dateTime": "2018-04-30T13:00:00.0000000Z", "timeZone": "UTC" }, "end": { "dateTime": "2018-04-30T13:30:00.0000000Z", "timeZone": "UTC" }, "serviceLocation": { "displayName": "Customer location (987 Third Avenue, Buffalo, NY 98052, USA)", "locationEmailAddress": null, "locationUri": "", "locationType": null, "uniqueId": null, "uniqueIdType": null, "address": { "type": "home", "postOfficeBox": "", "street": "", "city": "", "state": "", "countryOrRegion": "", "postalCode": "" }, "coordinates": { "altitude": null, "latitude": null, "longitude": null, "accuracy": null, "altitudeAccuracy": null } }, "reminders": [], "invoiceDate": { "dateTime": "2018-04-30T13:30:00.0000000Z", "timeZone": "UTC" } }, { "id": "AAMkADKnAAA=", "selfServiceAppointmentId": "00000000-0000-0000-0000-000000000000", "customerId": "7ed53fa5-9ef2-4f2f-975b-27447440bc09", "customerName": "Jordan Miller", "customerEmailAddress": "jordanm#contoso.com", "customerPhone": "213-555-0199", "customerNotes": null, "serviceId": "57da6774-a087-4d69-b0e6-6fb82c339976", "serviceName": "Catered bento", "duration": "PT30M", "preBuffer": "PT5M", "postBuffer": "PT10M", "priceType": "fixedPrice", "price": 10, "serviceNotes": null, "optOutOfCustomerEmail": false, "staffMemberIds": [], "invoiceAmount": 10, "invoiceId": "1001", "invoiceStatus": "open", "invoiceUrl": "theInvoiceUrl", "customerLocation": { "displayName": "Customer", "locationEmailAddress": null, "locationUri": "", "locationType": null, "uniqueId": null, "uniqueIdType": null, "address": { "type": "home", "postOfficeBox": "", "street": "", "city": "", "state": "", "countryOrRegion": "", "postalCode": "" }, "coordinates": { "altitude": null, "latitude": null, "longitude": null, "accuracy": null, "altitudeAccuracy": null } }, "start": { "dateTime": "2018-05-01T12:00:00.0000000Z", "timeZone": "UTC" }, "end": { "dateTime": "2018-05-01T12:30:00.0000000Z", "timeZone": "UTC" }, "serviceLocation": { "displayName": "Customer location (123 First Avenue, Buffalo, NY 98052, USA)", "locationEmailAddress": null, "locationUri": "", "locationType": null, "uniqueId": null, "uniqueIdType": null, "address": { "type": "home", "postOfficeBox": "", "street": "", "city": "", "state": "", "countryOrRegion": "", "postalCode": "" }, "coordinates": { "altitude": null, "latitude": null, "longitude": null, "accuracy": null, "altitudeAccuracy": null } }, "reminders": [], "invoiceDate": { "dateTime": "2018-05-01T12:30:00.0000000Z", "timeZone": "UTC" } } ] } And this is what im getting for the start and end date time: start: dateTime: "0001-01-01T00:00:00.0000000Z" timeZone: "Etc/UTC" end: dateTime: "0001-01-01T00:00:00.0000000Z" timeZone: "Etc/UTC" I dont know what i'm doing wrong, i'd appreciate any help.
So for some reason using this URL: GET /bookingBusinesses/{id}/calendarView?start={start-value}&end={end-value} did end up giving me the exact results i was looking with correct time and everything the list appointments url was giving me. I guess that's why this is still in BETA
How to calculate the number of occurrences an attribute appear in a JSON array using javascript?
I have retrieved a JSON object from a public data API which look similar to following. [ { "category": "Burglary", "location_type": "Force", "location": { "latitude": "51.497877", "street": { "id": 953834, "name": "On or near Major Road" }, "longitude": "-0.064175" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 53832838, "location_subtype": "", "month": "2016-12" }, { "category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.497877", "street": { "id": 953834, "name": "On or near Major Road" }, "longitude": "-0.064175" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 53832841, "location_subtype": "", "month": "2016-12" }, { "category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.497877", "street": { "id": 953834, "name": "On or near Major Road" }, "longitude": "-0.064175" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 53832849, "location_subtype": "", "month": "2016-12" }, { "category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.500440", "street": { "id": 953881, "name": "On or near Chambers Street" }, "longitude": "-0.066891" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 53832881, "location_subtype": "", "month": "2016-12" } ] I am trying to count how many crimes happened in each category. Is it correct to access category value as 'obj[0].category' ? What would be the best way to count them?
Assuming you've parsed the JSON to get an array of objects, you can use the array .reduce() method to count the categories. .reduce() calls the function that you pass it once for each item in your array, passing as arguments an "accumulator" acc, which in this case will be an object {}, and the current array value crime. var data = // your data here var categories = data.reduce(function(acc, crime) { if (!acc[crime.category]) // if current category not in acc object acc[crime.category] = 1; // add it to acc with value 1 else // otherwise (it exists), so acc[crime.category]++; // increment it return acc; }, {}); The result will be an object like this: { "Burglary": 1, "anti-social-behaviour": 3 } ...so if you want to know how many burglaries occurred you could say categories["Burglary"]. (Expand and run the following snippet to see it work...) var data = [ { "category": "Burglary", "location_type": "Force", "location": { "latitude": "51.497877", "street": { "id": 953834, "name": "On or near Major Road" }, "longitude": "-0.064175" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 53832838, "location_subtype": "", "month": "2016-12" }, { "category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.497877", "street": { "id": 953834, "name": "On or near Major Road" }, "longitude": "-0.064175" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 53832841, "location_subtype": "", "month": "2016-12" }, { "category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.497877", "street": { "id": 953834, "name": "On or near Major Road" }, "longitude": "-0.064175" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 53832849, "location_subtype": "", "month": "2016-12" }, { "category": "anti-social-behaviour", "location_type": "Force", "location": { "latitude": "51.500440", "street": { "id": 953881, "name": "On or near Chambers Street" }, "longitude": "-0.066891" }, "context": "", "outcome_status": null, "persistent_id": "", "id": 53832881, "location_subtype": "", "month": "2016-12" } ] var categories = data.reduce(function(acc, crime) { if (!acc[crime.category]) acc[crime.category] = 1; else acc[crime.category]++; return acc; }, {}); console.log(categories); console.log(categories["Burglary"]); Note that there's no such thing as a JSON object. Either you have JSON, which is a string representation/serialisation of your array/object, or you have an actual array or object.
Another approach, using Array#forEach. var json = [{category:"Burglary",location_type:"Force",location:{latitude:"51.497877",street:{id:953834,name:"On or near Major Road"},longitude:"-0.064175"},context:"",outcome_status:null,persistent_id:"",id:53832838,location_subtype:"",month:"2016-12"},{category:"anti-social-behaviour",location_type:"Force",location:{latitude:"51.497877",street:{id:953834,name:"On or near Major Road"},longitude:"-0.064175"},context:"",outcome_status:null,persistent_id:"",id:53832841,location_subtype:"",month:"2016-12"},{category:"anti-social-behaviour",location_type:"Force",location:{latitude:"51.497877",street:{id:953834,name:"On or near Major Road"},longitude:"-0.064175"},context:"",outcome_status:null,persistent_id:"",id:53832849,location_subtype:"",month:"2016-12"},{category:"anti-social-behaviour",location_type:"Force",location:{latitude:"51.500440",street:{id:953881,name:"On or near Chambers Street"},longitude:"-0.066891"},context:"",outcome_status:null,persistent_id:"",id:53832881,location_subtype:"",month:"2016-12"}], result = {}; json.forEach(function(v){ !result[v.category] ? result[v.category] = 1 : result[v.category] += 1; }); console.log(result);
Use Array.prototype.reduce() function: var data = [{category:"Burglary",location_type:"Force",location:{latitude:"51.497877",street:{id:953834,name:"On or near Major Road"},longitude:"-0.064175"},context:"",outcome_status:null,persistent_id:"",id:53832838,location_subtype:"",month:"2016-12"},{category:"anti-social-behaviour",location_type:"Force",location:{latitude:"51.497877",street:{id:953834,name:"On or near Major Road"},longitude:"-0.064175"},context:"",outcome_status:null,persistent_id:"",id:53832841,location_subtype:"",month:"2016-12"},{category:"anti-social-behaviour",location_type:"Force",location:{latitude:"51.497877",street:{id:953834,name:"On or near Major Road"},longitude:"-0.064175"},context:"",outcome_status:null,persistent_id:"",id:53832849,location_subtype:"",month:"2016-12"},{category:"anti-social-behaviour",location_type:"Force",location:{latitude:"51.500440",street:{id:953881,name:"On or near Chambers Street"},longitude:"-0.066891"},context:"",outcome_status:null,persistent_id:"",id:53832881,location_subtype:"",month:"2016-12"}], counts = data.reduce(function (r, o) { (r[o.category])? r[o.category]++ : r[o.category] = 1; return r; }, {}); console.log(counts);
You can do it with Array#reduce, var arr = [{ "category": "Burglary", }, { "category": "anti-social-behaviour", }, { "category": "anti-social-behaviour", }, { "category": "anti-social-behaviour", }]; var results = arr.reduce(function(result, itm){ return (result[itm.category] = (result[itm.category] || 0) + 1, result); }, {}); console.log(results); //Object {Burglary: 1, anti-social-behaviour: 3} DEMO
Use Javascript object variable for an if statement
I'm using javascript to display information of a shop basket. I know how to pull the data and create elements from it, but I need to use one of the variables for an if statement, and am unsure how to. If this is true: "isPunchOut": false, then I want to target that with jQuery, and do something like $(".button").remove(); How do I do this? var retailerData = { "del": { "zip": "", "city": "" }, "user": { "country": "", "phone": "", "nbrOrders": 0, "isPunchOut": false, "name": "", "salesPerson": "", "customerNo": "", "email": "" }, "order": { "shippingSum": 0.0, "shippingFormatSum": "\u20AC0", "orderno": "0", "orderFormatSum": "\u20AC130", "voucher": "", "orderFormatVat": "\u20AC27,30", "currencySymbol": "\u20AC", "currency": "EUR", "orderVat": 27.3, "orderSum": 130.0, "items": [{ "imageURI": "\/imgr\/8c82380c-65f5-43aa-83ad-fae1215b5b39\/70\/70", "qtyAvail": 7, "price": 130.0, "qty": 1, "artno": "D630-T7100-GE-REF", "vat": 27.3, "formatVat": "\u20AC27,30", "id": "52307", "label": "D630 C2D-T7100/2GB/80GB/DVD/14"/NO COA WLAN", "category": "Computers - Notebooks", "formatPrice": "\u20AC130", "manufacturer": "Dell" }] } }
You can take a look at below JS code for reference: var isPunchOut = retailerData["user"]["isPunchOut"]; if(isPunchOut === false) $(".button").remove();
I would say you should try some code first and put where you get stuck .We not here to write code for your problems. var retailerData = { "del": { "zip": "", "city": "" }, "user": { "country": "", "phone": "", "nbrOrders": 0, "isPunchOut": false, "name": "", "salesPerson": "", "customerNo": "", "email": "" }, "order": { "shippingSum": 0.0, "shippingFormatSum": "\u20AC0", "orderno": "0", "orderFormatSum": "\u20AC130", "voucher": "", "orderFormatVat": "\u20AC27,30", "currencySymbol": "\u20AC", "currency": "EUR", "orderVat": 27.3, "orderSum": 130.0, "items": [{ "imageURI": "\/imgr\/8c82380c-65f5-43aa-83ad-fae1215b5b39\/70\/70", "qtyAvail": 7, "price": 130.0, "qty": 1, "artno": "D630-T7100-GE-REF", "vat": 27.3, "formatVat": "\u20AC27,30", "id": "52307", "label": "D630 C2D-T7100/2GB/80GB/DVD/14"/NO COA WLAN", "category": "Computers - Notebooks", "formatPrice": "\u20AC130", "manufacturer": "Dell" }] } } if(retailerData.user.isPunchOut){ //your jquery operation } Checkjsfiddle
What about? if (!retailerData.user.isPunchOut) { $(".button").remove(); }
Javascript & Nested JSON issues
So I'm trying to put together some JSON and parse it out into jquery but I am doing something wrong with my JSON syntax. I tried running it through a validator but it doesn't really tell me what I'm doing wrong. Can somebody point out the error of my ways? var searchresults = [ { "providerlisting": [ { "nametitle": "Cory M Spears, MD, FACP", "caretype": "Internal Medicine", "preferredProvider": true, "address1": "289 N. Highland Ave.", "address2": "", "cityStateZip": "Atlanta, GA 30306", "coverage": "/images/example.png", "status": "Out of Network", "psn": "", "dcontact": "urlhere", "save": "urlhere", "rating": "urlhere", }, { "nametitle": "Jimmy Dean, MD, FACP", "caretype": "External Medicine", "preferredProvider": false, "address1": "3 Piedmont Rd.", "address2": "", "cityStateZip": "Atlanta, GA 30706", "coverage": "/images/example2.png", "status": "In Network", "psn": "urlhere", "dcontact": "urlhere", "save": "urlhere", "rating": "urlhere", }, { "nametitle": "John Doe, DD, PM", "caretype": "Internal Medicine", "preferredProvider": true, "address1": "500 Ponce De Leon Ave", "address2": "Suite 5", "cityStateZip": "Atlanta, GA 30706", "coverage": "/images/example2.png", "status": "Out of Network", "psn": "urlhere", "dcontact": "urlhere", "save": "urlhere", "rating": "urlhere", }] }, { "categories": [{ "categoryMenu": [ { "providertype": [ { "title": "Doctor", "link": "#doctor", "amount": "400" }, { "title": "Hospital", "link": "#hospital", "amount": "40" }, { "title": "Urgent Care", "link": "#urgentCare", "amount": "37" } ] }, { "specialty": [ { "title": "Allergy and Immunology", "link": "#allergyAndImmunology", "amount": "2" }, { "title": "Audiology", "link": "#audiology", "amount": "3" }, { "title": "Allergy and Immunology", "link": "#allergyAndImmunology", "amount": "6" }, { "title": "Ambulatory Surgical Center", "link": "#ambulatorySurgicalCenter", "amount": "4" } ] }, { "gender": [ { "title": "Male", "link": "#male", "amount": "67" }, { "title": "Female", "link": "#female", "amount": "3" } ] } }] }];
Remove the , at the end of each "rating": "urlhere" there was a ] missing on the third last line, below is a valid json object var searchresults = [{ "providerlisting": [{ "nametitle": "Cory M Spears, MD, FACP", "caretype": "Internal Medicine", "preferredProvider": true, "address1": "289 N. Highland Ave.", "address2": "", "cityStateZip": "Atlanta, GA 30306", "coverage": "/images/example.png", "status": "Out of Network", "psn": "", "dcontact": "urlhere", "save": "urlhere", "rating": "urlhere" }, { "nametitle": "Jimmy Dean, MD, FACP", "caretype": "External Medicine", "preferredProvider": false, "address1": "3 Piedmont Rd.", "address2": "", "cityStateZip": "Atlanta, GA 30706", "coverage": "/images/example2.png", "status": "In Network", "psn": "urlhere", "dcontact": "urlhere", "save": "urlhere", "rating": "urlhere" }, { "nametitle": "John Doe, DD, PM", "caretype": "Internal Medicine", "preferredProvider": true, "address1": "500 Ponce De Leon Ave", "address2": "Suite 5", "cityStateZip": "Atlanta, GA 30706", "coverage": "/images/example2.png", "status": "Out of Network", "psn": "urlhere", "dcontact": "urlhere", "save": "urlhere", "rating": "urlhere" }] }, { "categories": [{ "categoryMenu": [{ "providertype": [{ "title": "Doctor", "link": "#doctor", "amount": "400" }, { "title": "Hospital", "link": "#hospital", "amount": "40" }, { "title": "Urgent Care", "link": "#urgentCare", "amount": "37" }] }, { "specialty": [{ "title": "Allergy and Immunology", "link": "#allergyAndImmunology", "amount": "2" }, { "title": "Audiology", "link": "#audiology", "amount": "3" }, { "title": "Allergy and Immunology", "link": "#allergyAndImmunology", "amount": "6" }, { "title": "Ambulatory Surgical Center", "link": "#ambulatorySurgicalCenter", "amount": "4" }] }, { "gender": [{ "title": "Male", "link": "#male", "amount": "67" }, { "title": "Female", "link": "#female", "amount": "3" }] }] }] }];
There are only , commas after a key/value pairs in objects if there is another one following it. (Same goes for Arrays as well) For example: var a = { key : 'value', keyB : 'value' // <-- there is no trailing comma before an object ends };
Do you know http://jsonlint.com/? You have to realise, an object in javascript is nearly the same like an associative array. I think you should read a bit more about Objects and Arrays in Javascript. Try this: var searchresults = { "providerlisting": [ { "nametitle": "Cory M Spears, MD, FACP", "caretype": "Internaenter code herel Medicine", "preferredProvider": true, "address1": "289 N. Highland Ave.", "address2": "", "cityStateZip": "Atlanta, GA 30306", "coverage": "/images/example.png", "status": "Out of Network", "psn": "", "dcontact": "urlhere", "save": "urlhere", "rating": "urlhere" }, { "nametitle": "Jimmy Dean, MD, FACP", "caretype": "External Medicine", "preferredProvider": false, "address1": "3 Piedmont Rd.", "address2": "", "cityStateZip": "Atlanta, GA 30706", "coverage": "/images/example2.png", "status": "In Network", "psn": "urlhere", "dcontact": "urlhere", "save": "urlhere", "rating": "urlhere" }, { "nametitle": "John Doe, DD, PM", "caretype": "Internal Medicine", "preferredProvider": true, "address1": "500 Ponce De Leon Ave", "address2": "Suite 5", "cityStateZip": "Atlanta, GA 30706", "coverage": "/images/example2.png", "status": "Out of Network", "psn": "urlhere", "dcontact": "urlhere", "save": "urlhere", "rating": "urlhere" } ], "categories": { "categoryMenu": { "providertype": [ { "title": "Doctor", "link": "#doctor", "amount": "400" }, { "title": "Hospital", "link": "#hospital", "amount": "40" }, { "title": "Urgent Care", "link": "#urgentCare", "amount": "37" } ], "specialty": [ { "title": "Allergy and Immunology", "link": "#allergyAndImmunology", "amount": "2" }, { "title": "Audiology", "link": "#audiology", "amount": "3" }, { "title": "Allergy and Immunology", "link": "#allergyAndImmunology", "amount": "6" }, { "title": "Ambulatory Surgical Center", "link": "#ambulatorySurgicalCenter", "amount": "4" } ], "gender": [ { "title": "Male", "link": "#male", "amount": "67" }, { "title": "Female", "link": "#female", "amount": "3" } ] } } }
Please find the corrected Json string var searchresults = [ { "providerlisting": [ { "nametitle": "Cory M Spears, MD, FACP", "caretype": "Internal Medicine", "preferredProvider": true, "address1": "289 N. Highland Ave.", "address2": "", "cityStateZip": "Atlanta, GA 30306", "coverage": "/images/example.png", "status": "Out of Network", "psn": "", "dcontact": "urlhere", "save": "urlhere", "rating": "urlhere", }, { "nametitle": "Jimmy Dean, MD, FACP", "caretype": "External Medicine", "preferredProvider": false, "address1": "3 Piedmont Rd.", "address2": "", "cityStateZip": "Atlanta, GA 30706", "coverage": "/images/example2.png", "status": "In Network", "psn": "urlhere", "dcontact": "urlhere", "save": "urlhere", "rating": "urlhere", }, { "nametitle": "John Doe, DD, PM", "caretype": "Internal Medicine", "preferredProvider": true, "address1": "500 Ponce De Leon Ave", "address2": "Suite 5", "cityStateZip": "Atlanta, GA 30706", "coverage": "/images/example2.png", "status": "Out of Network", "psn": "urlhere", "dcontact": "urlhere", "save": "urlhere", "rating": "urlhere", }] }, { "categories": [{ "categoryMenu": [ { "providertype": [ { "title": "Doctor", "link": "#doctor", "amount": "400" }, { "title": "Hospital", "link": "#hospital", "amount": "40" }, { "title": "Urgent Care", "link": "#urgentCare", "amount": "37" } ] }, { "specialty": [ { "title": "Allergy and Immunology", "link": "#allergyAndImmunology", "amount": "2" }, { "title": "Audiology", "link": "#audiology", "amount": "3" }, { "title": "Allergy and Immunology", "link": "#allergyAndImmunology", "amount": "6" }, { "title": "Ambulatory Surgical Center", "link": "#ambulatorySurgicalCenter", "amount": "4" } ] }, { "gender": [ { "title": "Male", "link": "#male", "amount": "67" }, { "title": "Female", "link": "#female", "amount": "3" } ] } ] }] }]; alert(JSON.stringify(searchresults))