Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions stdlib/std.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ limitations under the License.
local arr = std.split(f, '/');
std.join('/', std.makeArray(std.length(arr) - 1, function(i) arr[i]) + [r]),

prune(a)::
prune(a, ex=[])::
local isContent(b) =
if b == null then
false
Expand All @@ -1622,11 +1622,11 @@ limitations under the License.
else
true;
if std.isArray(a) then
[std.prune(x) for x in a if isContent($.prune(x))]
[$.prune(x, ex) for x in a if isContent($.prune(x, ex))]
else if std.isObject(a) then {
[x]: $.prune(a[x])
[x]: $.prune(a[x], ex)
for x in std.objectFields(a)
if isContent(std.prune(a[x]))
if std.member(ex, x) || isContent($.prune(a[x], ex))
} else
a,

Expand Down
2 changes: 2 additions & 0 deletions test_suite/stdlib.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,8 @@ std.assertEqual(std.prune([[], {}, null]), []) &&
std.assertEqual(std.prune({ a: [[], {}, null], b: { a: [], b: {}, c: null } }), {}) &&
std.assertEqual(std.prune([[[], {}, null], { a: [], b: {}, c: null }]), []) &&
std.assertEqual(std.prune({ a: [{ b: true }] }), { a: [{ b: true }] }) &&
std.assertEqual(std.prune({ a: [{ b: [] }] }, ['b']), { a: [{ b: [] }] }) &&


std.assertEqual(std.parseJson('"foo"'), 'foo') &&
std.assertEqual(std.parseJson('{}'), {}) &&
Expand Down