flightcontrolhq / superjson

Safely serialize JavaScript expressions to a superset of JSON, which includes Dates, BigInts, and more.
https://www.flightcontrol.dev?ref=superjson
MIT License
4.02k stars 87 forks source link

"undefined" in meta #229

Closed epicmau5time closed 1 year ago

epicmau5time commented 1 year ago

When returning a list from the db with a ton of potential undefined fields, superjson just crams a ton of undefined's in meta:

Actual data: 1711 lines, Data + Meta: 3028 lines.

Is there a way to prevent superjson from adding "undefined" fields to meta?

Or is that just how superjson works?

image

Skn0tt commented 1 year ago

Hi @epicmau5time! Yes, that's how SuperJSON works. If you want to prevent this, you could delete the unwanted properties.

Some Background: In JavaScript, there's a difference between a property not existing, and it having the value undefined. We tend to call both things "being undefined", but they behave slightly different. e.g. Object.keys({}) === [], whereas Object.keys({ foo: undefined }) === ["foo"]. That's why SuperJSON makes a difference here.