I have a very big Json file (dataset is bigger then 30 000) . I need to check if a part of the value of a certain key is the same as a given string and then increment an int.
This is part of the Json:
[
{
"geo": null,
"coordinates": null,
"in_reply_to_status_id_str": null,
"contributors": null,
"in_reply_to_user_id": null,
"in_reply_to_status_id": null,
"truncated": false,
"created_at": "Tue Nov 13 20:17:17 +0000 2012"
I want to check if the key “created_at” has a certain day(value). Like for example ‘Tue’
and then increment : var tuesday = 0;
only thing i could come up with is this function:
function getValues(obj, key) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == 'object') {
objects = objects.concat(getValues(obj[i], key));
} else if (i == key) {
objects.push(obj[i]);
}
}
return objects;
}
But it only checks the key and puts the value in an array. That is not what i want.
It is not immediately clear from your question what the structure of the data is, but it looks to be an array of objects where the created_at property will be populated with a Date. If you need it to be recursive (which the code you provided suggests) the following code would need modification. But going off the description:
Then the following will take the array as
dataand result in the variablevaluecontaining an object with a map of days and the number of items where thecreated_atproperty begins with each of the 7 day of week strings.result would resemble: