After coming across a post on Stack Overflow, I realized it wasn't exactly what I needed. My JSON file is quite large and has the following 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 that represents this object and can extract its properties and sub-objects. The foo
property is required while the presence of the bar
property is optional. The data
property can be an array of varying dimensions. The lengths of both foo
and data
are always the same. Now, I want to reduce the content size of the file while preserving its structure by creating a new object with a shorter length or range based on specified criteria. For example, if I specify from foo[0]
to foo[1]
, then the data
property should also follow suit from data[0]
to data[1]
in the new object.
Is this achievable? If so, how can I go about it? Perhaps utilizing the map
method? But how?
function filter(obj, from, to){
/// ?
}
Thank you.
EDIT:
The resulting reduced object should resemble 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]
}
]
}