Recursively strip empty/null/zero values from JSON-like structures
{
"deps": {
"0xA672/strip": "main"
}
}moon updateimport {
"0xA672/strip" @strip
}///|
import {
"moonbitlang/core/debug"
}
fn main {
let input : @strip.Js = @strip.Ob(Map[String, Js]::of([
("name", @strip.St("Alice")),
("age", @strip.Nu(0.0)),
("address", @strip.Nl),
("hobbies", @strip.Ar([])),
("meta", @strip.Ob(Map[String, Js]::of([
("active", @strip.Bl(false)),
("score", @strip.Nu(0.0))
])))
]))
let cleaned = @strip.strip(input, true)
debug_inspect(cleaned)
// Output: Ob({name: St("Alice"), meta: Ob({active: Bl(false)})})
}💡 Note: The Js enum derives Debug (not Show) because standard library container types (Array, Map) have deprecated Show implementations. Use debug_inspect() or @debug.to_string() for output.
| Type | Stripped when |
|---|---|
| Nl | always |
| Ar([]) | always or all children stripped |
| Ob({}) | no fields left after cleaning |
| Nu(0.0) | oz == true in strip() |
| St("") | always in strip() / strip_empty() |
| Bl(_) | never |
moon build
moon test
moon fmtInstall
Download zipRecursively strip empty/null/zero values from JSON-like structures