Creating A Dictionary For JSON Keys?
nickreese opened this issue · 1 comments
Hey Rich! Love this library and use it every time we mount a component to HTML in Elder.js.
One project our team is tackling has a pretty large JSON object we need to hydrate which has a lot of repeated keys.
Currently devalue
gives us an output which looks something like this:
// function... yada yada
[
{
plant_id: 9456,
plant_code: '61264',
plant_name: 'Antelope Expansion 2',
toxic_chemical_release: a,
primary_fuel: q,
address: ab,
longitude: -118.309153,
latitude: 34.744977,
owners: [{ provider_id: C, provider_eiaid: v, provider_name: a, provider_slug: v, fraction_owned: n }],
plant_production_time_periods: [i, f, l, h, c, g, m, j, k, d, e, b],
plant_emission_time_periods: [b, k, h, m, j, g, c, i, l, d, f, e],
plant_production_12_month: 250964,
plant_emission_12_month: 24580147.654842217,
plant_emission_per_mwh: 97.94292270940142,
},
{
plant_id: 4817,
plant_code: '56041',
plant_name: 'Malburg',
toxic_chemical_release: a,
primary_fuel: o,
address: '4963 Soto Street',
longitude: -118.2219,
latitude: 33.9986,
owners: [{ provider_id: a, provider_eiaid: a, provider_name: a, provider_slug: a, fraction_owned: n }],
plant_production_time_periods: [b, j, c, i, e, k, f, g, h, d, m, l],
plant_emission_time_periods: [h, k, m, f, b, j, d, c, l, e, i, g],
plant_production_12_month: 376645,
plant_emission_12_month: 264428563.37669998,
plant_emission_per_mwh: 702.0631187901074,
},
{
plant_id: 4821,
plant_code: '56051',
plant_name: 'THUMS',
toxic_chemical_release: a,
primary_fuel: o,
address: '1411 Pier D Street',
longitude: -118.2141,
latitude: 33.7684,
owners: [{ provider_id: a, provider_eiaid: a, provider_name: a, provider_slug: a, fraction_owned: n }],
plant_production_time_periods: [g, e, c, d, j, m, h, b, k, f, l, i],
plant_emission_time_periods: [b, h, c, l, k, m, e, j, i, d, g, f],
plant_production_12_month: 356307,
plant_emission_12_month: 200655151.6458,
plant_emission_per_mwh: 563.1524265473314,
},
];
Any reason devalue
can't be extended to create a dictionary for keys so they can be compressed as well? Reading the source code I don't see a reason why it couldn't be, but I think you're much much more familiar with the esoterics of the ecosystem and alternatives than I am.
Just looking to compress the object sizes down with no cost to the client. devalue
is great at this. :)
Ended up rolling my own. Don't have a requirement for set
and map
so getting away from eval
made sense.