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

Skip empty nodes at serialization #121

Open
jrodriguez-rc opened this issue Aug 25, 2022 · 2 comments
Open

Skip empty nodes at serialization #121

jrodriguez-rc opened this issue Aug 25, 2022 · 2 comments

Comments

@jrodriguez-rc
Copy link
Contributor

This new option will skip all the nodes that have no content:

  • Simple node values empty/null
  • Structures/Arrays with no subnodes
@sbcgua
Copy link
Owner

sbcgua commented Aug 30, 2022

Do you mean without filter ? https://github.com/sbcgua/ajson#predefined-filters

Also:

  • structures/arrays should be ok
  • but values are not. Is false empty ? Or null ? Or 0. I think not always.

@mbtools
Copy link
Contributor

mbtools commented May 30, 2024

I would go with the most famous isEmpty implementation:
https://github.com/lodash/lodash/blob/main/src/isEmpty.ts

It's working differently now:

method zif_ajson_filter~keep_node.
rv_keep = boolc(
( iv_visit = zif_ajson_filter=>visit_type-value and is_node-value is not initial ) or
( iv_visit <> zif_ajson_filter=>visit_type-value and is_node-children > 0 ) ).
" children = 0 on open for initially empty nodes and on close for filtered ones
endmethod.

I changed my custom empty filter to the following which also removes null and initial numbers (zero).

    rv_keep = boolc(
      ( iv_visit = zif_ajson_filter=>visit_type-value AND
        ( is_node-type = zif_ajson_types=>node_type-string AND is_node-value IS NOT INITIAL OR
          is_node-type = zif_ajson_types=>node_type-boolean OR
          is_node-type = zif_ajson_types=>node_type-number AND is_node-value <> 0 ) ) OR
      ( iv_visit <> zif_ajson_filter=>visit_type-value AND is_node-children > 0 ) ).

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

No branches or pull requests

3 participants