Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove null or None from JSON? #30

Open
nensor opened this issue May 4, 2021 · 3 comments · May be fixed by #55
Open

Remove null or None from JSON? #30

nensor opened this issue May 4, 2021 · 3 comments · May be fixed by #55

Comments

@nensor
Copy link

nensor commented May 4, 2021

Using the serializer successfully with my data model, but I was wondering if there's a simple way to get it to filter out "null" items when serializing models or dictionaries?

My data is pulled from Postgresql, and as I'm feeding much of it to SOLR for indexing purposes, I'd like to reduce the document size and eliminate unneeded elements from the JSON output. If there's already an option in the Serializer I'm missing or an easy way to accomplish this via the model, I'd appreciate a pointer.

Thanks in advance.

@n0nSmoker
Copy link
Owner

So basically you need to get smth like this:
{'key':{'key1': True}
instead of this:
{'key':{'key1': True, 'key2': None}
Am I right?

@n0nSmoker
Copy link
Owner

To filter out specific values, not keys?

@n0nSmoker
Copy link
Owner

If so I can add an option for you, it doesn't look difficult and should not affect performance.
Smth like the following:
model.to_dict(only=('...',), sieve=lambda x: x is not None)

@n0nSmoker n0nSmoker linked a pull request Jul 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants