armincms / json

A laravel nova field
MIT License
26 stars 2 forks source link

Filter the output json for null values #2

Closed bernhardh closed 4 years ago

bernhardh commented 4 years ago

If you save the json field, in your current version, null values are stored as well. To make the json more readable and save db space, just filter the data.

Instead of (for example)

{
    "name": "My Name",
    "surname": null,
    "lastname": null,
    "email": "office@example.com",
    "birthdate": null,
    "gender": null
}

you will get

{
    "name": "My Name",
    "email": "office@example.com",
}
zareismail commented 4 years ago

I think this is not a good idea. because some values need to store as null. suppose you have data named x that have default value y and accept a null value. what happens if a user sets the null value for it and the package filter it? thanks for contribution.

zareismail commented 4 years ago

If you save the json field, in your current version, null values are stored as well. To make the json more readable and save db space, just filter the data.

Instead of (for example)

{
    "name": "My Name",
    "surname": null,
    "lastname": null,
    "email": "office@example.com",
    "birthdate": null,
    "gender": null
}

you will get

{
    "name": "My Name",
    "email": "office@example.com",
}

Hey. You can use version 0.4.0 and take advantage of the nullable. feature refer here

bernhardh commented 4 years ago

Thank you very much! Great job. Thats the best solution, to make it optional, so you can hit both scenarios - mine and yours ;)