kind() - > string- Module
- std.
json - Receiver
- JSON
Value - Minimum arity
- 0
- Maximum arity
- 0
Declaration and parameters
LinkAvailability
Included by default: Pending
Import std.json in language mode 5.21.
The current compiler selects std/json.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1158 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 68 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1158 - compiler/crates/topaz_self_frontend/topaz/checker/builtin_signatures.tpz at
b48527d0a174· 401 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1296 - compiler/crates/topaz_value/src/value/members.rs at
b48527d0a174· 196
Receiver
JSONValue
Parameter constraints
JSON returns exactly one of null, bool, number, string, array, or object. The name describes the JSON value's outermost kind. Both true and false have kind bool. Integer and fractional JSON numbers have kind number.
Test whether a JSON value is null with value.. This comparison is false for false, zero, the empty string, and empty arrays and objects. Reading the kind does not modify or decode the JSON value.
A present array element or object member containing JSON null is still present. at and get return Some(value) containing that JSONValue. An absent element or member returns None(). Inspect presence first, then compare the contained value's kind.
JSONValue does not expose an is member. Use the same kind comparison for null as for every other JSON kind.
Result
The declared result type is string.
Effects
Failures
Result and effects
LinkThe result is null, bool, number, string, array, or object. Compare it with "null" to test for JSON null. This query preserves the value and distinguishes stored null from an absent array element or object member.
Why
LinkOne query covers every JSON kind, and ordinary equality expresses each kind test.
Related entries
LinkInspect JSON kinds with kind
LinkInspect JSON kinds with kind
JSON returns exactly one of null, bool, number, string, array, or object. The name describes the JSON value's outermost kind. Both true and false have kind bool. Integer and fractional JSON numbers have kind number.
Test whether a JSON value is null with value.. This comparison is false for false, zero, the empty string, and empty arrays and objects. Reading the kind does not modify or decode the JSON value.
A present array element or object member containing JSON null is still present. at and get return Some(value) containing that JSONValue. An absent element or member returns None(). Inspect presence first, then compare the contained value's kind.
JSONValue does not expose an is member. Use the same kind comparison for null as for every other JSON kind.
Why
One kind query distinguishes every JSON value kind. Comparing that result uses the ordinary equality rule for null, booleans, numbers, strings, arrays, and objects. A separate null predicate would duplicate one case and give it a second spelling. Keeping presence separate also prevents a stored null from being mistaken for a missing entry.
Source evidence
- compiler/crates/topaz_value/src/value/members.rs at
72a59a31125f· 659 - compiler/crates/topaz_value/src/value/json/parser.rs at
72a59a31125f· 4 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
72a59a31125f· 1156 - compiler/crates/topaz_value/src/value/members.rs at
72a59a31125f· 698 -
topaz.stdlib.contract.json-kindatworking-tree - topaz.decision.json-kind-null.1 at
topaz.decisi
Distinguish null from every other JSON kind
Linkimport std.jsonimport std.testimport std.iofor source in (["null", "false", "0", "\"\"", "[]", "\{\}"]) {let value = test.assertOk(json.parse(source))let kind = value.kind()let nullKind = kind == "null"io.writeLine("{kind}:{nullKind}")}
null:true bool:false number:false string:false array:false object:false
Expected result
Expected result
Execution completes. Exit code 0.
null:truebool:falsenumber:falsestring:falsearray:falseobject:false
Source evidence
- compiler/crates/topaz_value/src/value/members.rs at
72a59a31125f· 659 - compiler/crates/topaz_value/src/value/json/parser.rs at
72a59a31125f· 4 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
72a59a31125f· 1156 - compiler/crates/topaz_value/src/value/members.rs at
72a59a31125f· 698 -
topaz.stdlib.contract.json-kindatworking-tree - topaz.decision.json-kind-null.1 at
topaz.decisi
Keep present null values distinct from missing entries
Linkimport std.jsonimport std.testimport std.iolet array = test.assertOk(json.parse("[null]"))let object = test.assertOk(json.parse("\{\"present\":null\}"))let arrayValue = test.assertSome(array.at(0))let objectValue = test.assertSome(object.get("present"))test.assertNone(array.at(1))test.assertNone(object.get("absent"))io.writeLine("{arrayValue.kind()}:{objectValue.kind()}")
null:null
Expected result
Expected result
Execution completes. Exit code 0.
null:null
Source evidence
- compiler/crates/topaz_value/src/value/members.rs at
72a59a31125f· 659 - compiler/crates/topaz_value/src/value/json/parser.rs at
72a59a31125f· 4 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
72a59a31125f· 1156 - compiler/crates/topaz_value/src/value/members.rs at
72a59a31125f· 698 -
topaz.stdlib.contract.json-kindatworking-tree - topaz.decision.json-kind-null.1 at
topaz.decisi
Reject the removed JSONValue.isNull member
Linkimport std.json { JSONValue }function inspect(value: JSONValue) -> () {let result = value.isNull()return ()}
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_value/src/value/members.rs at
72a59a31125f· 659 - compiler/crates/topaz_value/src/value/json/parser.rs at
72a59a31125f· 4 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
72a59a31125f· 1156 - compiler/crates/topaz_value/src/value/members.rs at
72a59a31125f· 698 -
topaz.stdlib.contract.json-kindatworking-tree - topaz.decision.json-kind-null.1 at
topaz.decisi
Use kind to test a JSON value for null
Linkimport std.json { JSONValue }function inspect(value: JSONValue) -> () {let result = value.kind() == "null"return ()}
No stdout.
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_value/src/value/members.rs at
72a59a31125f· 659 - compiler/crates/topaz_value/src/value/json/parser.rs at
72a59a31125f· 4 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
72a59a31125f· 1156 - compiler/crates/topaz_value/src/value/members.rs at
72a59a31125f· 698 -
topaz.stdlib.contract.json-kindatworking-tree - topaz.decision.json-kind-null.1 at
topaz.decisi