Skip to content

Conversation

@shrred26
Copy link
Contributor

@shrred26 shrred26 commented May 9, 2025

Implement std.isNull in standard library

go-jsonnet PR: google/go-jsonnet#806

@He-Pin
Copy link

He-Pin commented May 13, 2025

@shrred26 What's the usercase of this, to avoid the exception with if?

It would be nice to have ? and ?? in jsonnet.

@kalvdans
Copy link
Contributor

What is wrong with using v == null?

std.assertEqual(std.isArray([]), true) &&
std.assertEqual(std.isFunction(function() 0), true) &&
std.assertEqual(std.isNull(null), true) &&
std.assertEqual(std.isNull('foo'), false) &&
Copy link

@He-Pin He-Pin Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, nice addition.

@johnbartholomew johnbartholomew marked this pull request as draft January 26, 2026 11:45
@johnbartholomew johnbartholomew marked this pull request as ready for review January 26, 2026 11:45
@johnbartholomew
Copy link
Collaborator

Sorry for the long delay in looking at this. Although clearly not strictly a necessary addition (since x == null should work fine and is not notably longer than std.isNull(x)), I do see this is analogous to the type checking functions isString etc, so I think it makes sense to add it.

Thanks for the contribution!

@johnbartholomew johnbartholomew merged commit bd1f67e into google:master Jan 26, 2026
9 checks passed
He-Pin added a commit to He-Pin/sjsonnet that referenced this pull request Jan 26, 2026
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 this pull request may close these issues.

4 participants