Reputation: 2740
In my project I need to aggregate many data in one string and later parse it out. The data is related to people, it need to record people_ids in different state and age group, and their counts. For example, we have 5 people named John Smith in CA, 2 people between 20-29, 2 between 30-39, 1 between 40-49; 2 people named John Smith in NY, 1 between 20-29 and 1 between 30-39. Then the string will be somewhat like this,
John smith| [CA#5: 20-29#2{pid_1, pid_2};30-39#2{pid_3,pid_4};40-49#1{pid_5}] [NY#2: 20-29#1{pid_6};30-39#1{pid_7}]
It not necessarily be the same format, but whatever format easy to parse out. Is there any good way to do this? How about Json format? And if it looks like the above format, if I want all John Smith in CA between age 30-39, how should I parse out the data? Thanks a lot!!
Upvotes: 0
Views: 111
Reputation: 5205
From my understanding of your post, this might be a format you're looking for (as represented in JSON).
Keep in mind that there are gems that can generate and parse JSON for you.
{
"name": "John Smith",
"states": {
"CA": {
"total": 5,
"ages": {
"20-29": [pid_1, pid_2],
"30-39": [pid_3, pid_4],
"40-49": [pid_5]
}
},
"NY": {
"total": 2,
"ages": {
"20-29": [pid_6],
"30-39": [pid_7]
}
}
}
}
Upvotes: 2