I found this post but it's not really what I'm looking for. I have a huge JSON file with this structure:
{
foo: [1, 2, 3, ...],
bar: [
{
name: 'abc',
cl: 2,
data: [
[[2, 4, 6], [4, 5, 6]],
[[5, 3, 5], [5, 7, 9]],
[[6, 8, 9], [6, 8, 9]],
...
]
},
{
name: 'def',
cl: 1,
data: [10, 20, 30, ...]
}
]
}
I have a class representing the object and I can extract the properties and the objects inside the parent object. The foo property is mandatory while the bar property is optional. data is a numeric array that can be 1D or 3D. The foo.length and the data.length are always the same. I want to reduce the file size (in term of contents) but keeping the same structure, i.e. copy the old object to a new with exactly the same structure but shorter, so I could define a smaller length or range and get a new object, e.g. if I say to go from foo[0] to foo[1] then the data property will also go from data[0] to data[1] in the new object.
Is this possible? If yes, how can I achieve it? Maybe with map? but how?
function filter(obj, from, to){
/// ?
}
Regards.
EDIT:
The new reduced object should be something like this:
{
foo: [1, 2],
bar: [
{
name: 'abc',
cl: 2,
data: [
[[2, 4, 6], [4, 5, 6]],
[[5, 3, 5], [5, 7, 9]]
]
},
{
name: 'def',
cl: 1,
data: [10, 20]
}
]
}
foo[0]tofoo[1]. But it could be any range inside the length of thefoo.length. That will also affect the elements taken fromdata:foo.length = (bar with name 'abc').data.length = (bar with name 'def').data.lengthAndfoo[i]is related with(bar with name 'abc').data[i]and(bar with name 'def').data[i]