{"id":22750059,"url":"https://github.com/pwall567/kjson-test","last_synced_at":"2026-03-18T01:35:15.844Z","repository":{"id":57735742,"uuid":"395920529","full_name":"pwall567/kjson-test","owner":"pwall567","description":"Library for testing Kotlin JSON applications","archived":false,"fork":false,"pushed_at":"2025-06-24T15:20:00.000Z","size":341,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-10T07:09:53.901Z","etag":null,"topics":["json","kotlin","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pwall567.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-08-14T06:55:19.000Z","updated_at":"2025-06-24T15:19:27.000Z","dependencies_parsed_at":"2023-02-08T05:45:14.844Z","dependency_job_id":"9b985a3b-9afd-45f2-9335-495d93277eb4","html_url":"https://github.com/pwall567/kjson-test","commit_stats":null,"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"purl":"pkg:github/pwall567/kjson-test","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Fkjson-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Fkjson-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Fkjson-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Fkjson-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pwall567","download_url":"https://codeload.github.com/pwall567/kjson-test/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Fkjson-test/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30640251,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-18T00:09:27.587Z","status":"ssl_error","status_checked_at":"2026-03-18T00:09:26.123Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json","kotlin","unit-testing"],"created_at":"2024-12-11T04:11:51.195Z","updated_at":"2026-03-18T01:35:15.797Z","avatar_url":"https://github.com/pwall567.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kjson-test\n\n[![Build Status](https://github.com/pwall567/kjson-test/actions/workflows/build.yml/badge.svg)](https://github.com/pwall567/kjson-test/actions/workflows/build.yml)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Kotlin](https://img.shields.io/static/v1?label=Kotlin\u0026message=v2.0.21\u0026color=7f52ff\u0026logo=kotlin\u0026logoColor=7f52ff)](https://github.com/JetBrains/kotlin/releases/tag/v2.0.21)\n[![Maven Central](https://img.shields.io/maven-central/v/io.kjson/kjson-test?label=Maven%20Central)](https://central.sonatype.com/artifact/io.kjson/kjson-test)\n\nLibrary for testing Kotlin JSON applications\n\nThis library provides a convenient means of testing applications that produce JSON results.\nIt uses a Kotlin DSL to describe the expected JSON values, and produces helpful messages in the case of errors.\n\n## Contents\n\n- [Quick Start](#quick-start)\n- [User Guide](#user-guide)\n- [Dependency Specification](#dependency-specification)\n\nOr for a fuller description of the functions available, see the [`kjson-test` Reference Guide](REFERENCE.md).\n\n\n## Quick Start\n\n### Example\n\nIn a test class, the result of an operation (possibly an external client call) may be tested using `shouldMatchJSON`:\n```kotlin\n    @Test fun `should produce correct JSON name data`() {\n        val json = functionUnderTest()\n        // json is (for example):\n        // {\"data\":[{\"id\":1234,\"surname\":\"Walker\",\"givenNames\":[\"Richard\"]}]}\n        json shouldMatchJSON {\n            property(\"data\") {\n                item(0) {\n                    property(\"id\", 1234)\n                    property(\"surname\", \"Walker\")\n                    property(\"givenNames\") {\n                        count(1)\n                        item(0, \"Richard\")\n                    }\n                    propertyAbsent(\"birthDate\")\n                }\n            }\n        }\n    }\n```\n\n### The Problem\n\nMany Kotlin applications return their result in the form of a JSON object, or in some cases, as an array of JSON\nobjects.\nWhen we attempt to test these applications, we run into a simple problem \u0026ndash; there may be many valid JSON\nrepresentations of the same object.\nThe properties of a JSON object do not have a pre-determined order, and given a valid set of properties, any sequence of\nthose properties is equally valid.\n\nAlso, the JSON specification allows for whitespace to be added at many points in the JSON string, without affecting the\nmeaning of the content, and some primitive values may be output differently by different source systems:\n\n- `4000` is the same number as `4e3` (see [Floating Point](#floating-point) below)\n- `\"Hello\\n\"` is the same string as `\"Hello\\u000A\"`\n- `\"2025-06-22T12:00:00Z\"` is the same `OffsetDateTime` as `\"2025-06-22T12:00:00.000+00:00\"`\n\nAll of this means that it is not possible to test the results of a function returning JSON simply by performing a string\ncomparison on the output.\nWe need a means of checking the data content of the JSON, regardless of the formatting.\n\nMany developers avoid the problem by deserializing the JSON into the internal form of the object for comparison, but\nthat is not always a useful option.\nAnd there are libraries that will check an arbitrary JSON string, but they are mostly written in and for Java, and they\ndo not take advantage of the capabilities of Kotlin.\n\n### The Solution\n\nThe `kjson-test` library allows the expected content of a JSON object to be described in a simple, intuitive form,\nallowing functions returning JSON to be tested easily.\n\nIn many cases, the expected values will be known precisely, and the basic forms of comparison make a good starting\npoint:\n```kotlin\n    property(\"id\", 1234)\n    property(\"surname\", \"Walker\")\n```\nThis checks that the current node is an object with a property named \u0026ldquo;`id`\u0026rdquo; having the value 1234, and\nanother property \u0026ldquo;`surname`\u0026rdquo; with the value \u0026ldquo;`Walker`\u0026rdquo;.\n\nNested objects may be checked by:\n```kotlin\n    property(\"details\") {\n        // tests on the nested object\n    }\n```\n\nAnd array items can similarly be checked, either as primitive values or as nested objects or arrays.\n\nThe `kjson-test` library makes testing simple cases easy and clear, and at the same time provides functionality to\nmeet very broad and complex testing requirements.\n\n\n\n\n\n\n## User Guide\n\nFirst, some terminology:\n- a JSON **object** is the form of JSON structure enclosed in curly braces (` { } `) and containing a set of name-value\n  pairs\n- these pairs are called **properties**, and each has a property name, and a value which may be a primitive value or a\n  nested object or array\n- a JSON **array** is an ordered collection of values (possibly nested objects or arrays) enclosed in square brackets\n  (` [ ] `)\n- an **array item** is a member of an array\n- a JSON **value** is any of the possible JSON data types: a string, a number, a boolean, the value \u0026ldquo;`null`\u0026rdquo;\n  or a nested object or array\n\nA function or service returning a JSON result will usually return an object or an array of objects, but according to the\nJSON specification the string representation of any JSON value is a valid JSON string.\nThe `kjson-test` library provides facilities for testing all forms of JSON results.\n\n### Invoking the Tests\n\nThe set of tests on a JSON string is introduced by a call to the [`shouldMatchJson`](REFERENCE.md#shouldmatchjson)\nfunction.\nThis parses the JSON into an internal form and then performs the tests in the supplied lambda.\n```kotlin\n    stringToBeTested shouldMatchJSON {\n        // tests...\n    }\n```\n\nAn earlier form (still supported) uses a call to the [`expectJSON`](REFERENCE.md#expectjson) function.\nThe effect is the same, but the `shouldMatchJSON` syntax will probably be preferred by most users.\n```kotlin\n    expectJSON(stringToBeTested) {\n        // tests...\n    }\n```\n\nIf any of the tests fail, an `AssertionError` will be thrown with a detailed error message, usually including expected\nand actual values.\nThe message will in most cases be prefixed by the location in the JSON of the failing test in\n[JSON Pointer](https://tools.ietf.org/html/rfc6901) form.\n\nFor example:\n```text\n/data/0/surname: JSON value doesn't match - expected \"Wilson\", was \"Walker\"\n```\n\n### Testing JSON Properties\n\nThe [`property`](REFERENCE.md#property) function declares a test (or a group of tests) to be performed on a property of\nan object.\nThere are several forms of the `property` function; they all take a property name (`String`) as the first parameter, and\nan expected value or a lambda as the second.\nThe convention in Kotlin is that when an inline lambda is supplied as the last parameter to a function call, it should\nbe written after the closing parenthesis, as shown in the last of the examples below.\n\nSome examples:\n```kotlin\n        property(\"name\", \"William\")\n        property(\"id\", 12345678)\n        property(\"open\", true)\n        property(\"ref\", isUUID) // named lambda\n        property(\"details\") {   // inline lambda\n            // tests on nested object or array\n        }\n```\n\nThe `property` call with nested tests may be made more specific, to indicate whether a nested object or an array is\nexpected:\n```kotlin\n        propertyIsObject(\"details\") {\n            // tests on nested object\n        }\n        propertyIsArray(\"list\") {\n            // tests on nested array\n        }\n```\nThese functions confirm that the property is of the correct type before applying the nested tests.\nThis is not strictly necessary, since the first `property` test within the nested block will check that the current node\nis an object, but it does have documentation value.\n\nAnd if the property is an array, the array size may be checked in the same operation:\n```kotlin\n        propertyIsArray(\"list\", size = 2) {\n            // tests on nested array\n        }\n```\n\nFor both `propertyIsObject` and `propertyIsArray` the lambda with nested tests is optional, so they may be used to test\nthat a property is an object or an array respectively, with no testing of the contents.\n\n### Testing Array Items\n\nThe [`item`](REFERENCE.md#item) function declares a test (or a group of tests) to be performed on an item of an array.\nAs with `property`, there are several forms of the `item` function, each taking an index (`Int`) as the first parameter,\nand an expected value or a lambda as the second.\n\nSome examples:\n```kotlin\n        item(0, \"bear\")\n        item(27, -1)\n        item(1, true)\n        item(4) {\n            // tests on nested object or array\n        }\n```\n\nAs with property tests, if the array item is expected to be an object or an array, additional functions are available:\n```kotlin\n        itemIsObject(3) {\n            // tests on nested object\n        }\n        itemIsArray(0) {\n            // tests on nested array\n        }\n        itemIsArray(0, size = 2) {\n            // tests on nested array\n        }\n```\n\nWhere the array contains only primitive values, a [shorthand form](REFERENCE.md#items) is available:\n```kotlin\n        items(\"Tom\", \"Dick\", \"Harry\")\n```\nThis is equivalent to:\n```kotlin\n        count(3)\n        item(0, \"Tom\")\n        item(1, \"Dick\")\n        item(2, \"Harry\")\n```\n\nIn the case of a JSON array representing an unordered set, the [`anyItem`](REFERENCE.md#anyitem) function tests whether\nany item in an array matches the specified test.\nFor example, an authorisation function may return a set of permissions, but the order of the entries is immaterial:\n```kotlin\n        propertyIsArray(\"permissions\", size = 2) {\n            anyItem(\"customer:read\")\n            anyItem(\"product:read\")\n        }\n```\n(See also the section on [Exhaustive Checks](#exhaustive-checks) below.)\n\nAnd again, if the array item is expected to be an object or an array, additional functions are available:\n```kotlin\n        anyItemIsObject {\n            // tests on nested object\n        }\n        anyItemIsArray {\n            // tests on nested array\n        }\n        anyItemIsArray(size = 2) {\n            // tests on nested array\n        }\n```\n\n### Testing Primitive JSON Values\n\nIn rare cases a JSON string consists of a primitive value (string, number, boolean or `null`).\nThe [`value`](REFERENCE.md#value) function allows tests to be applied to the single primitive value, and it takes a\nsingle parameter, the expected value or lambda.\n\nSome examples:\n```kotlin\n        value(\"success\")\n        value(0)\n        value(false)\n        value(null)\n        value(isUUID)\n```\n\nThe `value` function can also be useful when more than one test is to be applied to a property or array item, for\nexample:\n```kotlin\n        property(\"name\") {\n            value(isNonBlankString)\n            value(length(1..30))\n        }\n```\n\n### Named Tests\n\nThe lambda parameter of the `property`, `item` or `value` tests normally takes the form of a set of tests to be applied\nto a nested object or array, but it can also specify a named lambda, as in the following examples:\n```kotlin\n        property(\"account\", isInteger)\n        item(0, isString)\n        property(\"id\", isUUID)\n        property(\"created\", isOffsetDateTime)\n```\n\nThese functions test that a property or item meets a particular requirement, without specifying the exact value.\nIn the above tests, the property \u0026ldquo;`account`\u0026rdquo; is checked to have an integer value, item 0 of an array\ncontains a string, property \u0026ldquo;`id`\u0026rdquo; contains a string formatted as a UUID and property\n\u0026ldquo;`created`\u0026rdquo; contains a string following the pattern of the `OffsetDateTime` class.\n\nSee the [Reference](REFERENCE.md) document for a full list of these [Named Lambdas](REFERENCE.md#named-lambdas).\n\n### Floating Point\n\nFloating point numbers are those with a decimal point, or using the scientific notation (_e.g._ `1.5e20`).\nMany decimal floating point numbers can not be represented with complete accuracy in a binary floating point system, so\nthe `kjson-test` library converts all such numbers to `BigDecimal`.\nThis means that tests on floating point numbers must use `BigDecimal`, or `ClosedRange\u003cBigDecimal\u003e`, or\n`Collection\u003cBigDecimal\u003e`.\n\nIf a comparison using a `BigDecimal` is performed against an `Int` or a `Long`, the value will be \u0026ldquo;widened\u0026rdquo;\nto `BigDecimal` before the test is performed.\n\nOne unusual feature of the `BigDecimal` class is that the `equals` comparison requires that both the value and the scale\nof the number must be equal, but this library uses `compareTo` to compare the values regardless of scale.\nIf it is important to confirm that a certain number of decimal digits are present (for example, in a money value), the\n[`scale`](REFERENCE.md#scale) function may be used to test the number of digits after the decimal point.\nAn `Int` or a `Long` will always be considered as having zero decimal places.\n\n### Dates and Times\n\nThe `java.time.XXXX` classes will accept dates and times formatted in different ways, but this can cause problems for\ncomparisons.\nFor example, the UTC+0 timezone may be represented by `+00:00` or by the letter `Z`, and fractional seconds may be\ntruncated if not significant.\n\nThe `kjson-test` library includes comparisons using the internal form of the date/time objects, so formatting\ndifferences will not cause tests to fail.\n```kotlin\n        property(\"created\", OffsetDateTime.parse(\"2025-06-25T15:30:00Z\"))\n```\nThe above test will succeed even if the JSON string contains `\"2025-06-25T15:30:00.000-00:00\"` or any other equally\nvalid representation of the same `OffsetDateTime`.\n\nIf it is important to check the exact format of the string, the comparison may be made using a `String` value.\n\n### Custom Deserialization\n\nThis library looks only at the input JSON, and does not take into account any custom deserializations that may be\napplied to the JSON when it is used in normal circumstances.\n\nFor example, custom name annotations are sometimes used to specify the name to be used as the JSON property name if it\ndiffers from the internal field name; in such cases the external JSON name must be used in the tests, not the field\nname.\n\n### Check for `null`\n\nChecking a value for `null`, _e.g._ `property(\"note\", null)` will check that the named property **is present** in the\nJSON object and has the value `null`.\nAlso, for convenience, a named lambda `isNull` will do the same thing.\n\nIn most cases, the fact that a property is not present in the JSON may be taken as being equivalent to the property\nbeing present with a `null` value.\nIf it is important to distinguish between a `null` property and an omitted property, there are functions which test\nspecifically for the presence or absence of a property:\n\n| To test that a property...                   | Use                                                                 |\n|----------------------------------------------|---------------------------------------------------------------------|\n| ...is present and is not null                | `property(\"name\", isNonNull)`                                       |\n| ...is present and is null                    | `property(\"name\", isNull)`                                          |\n| ...is present whether null or not            | [`propertyPresent(\"name\")`](REFERENCE.md#propertypresent)           |\n| ...is not present                            | [`propertyAbsent(\"name\")`](REFERENCE.md#propertyabsent)             |\n| ...is not present, or is present and is null | [`propertyAbsentOrNull(\"name\")`](REFERENCE.md#propertyabsentornull) |\n\nInstead of checking all of the properties that are expected not to be present using\n[`propertyAbsent(\"name\")`](REFERENCE.md#propertyabsent) or\n[`propertyAbsentOrNull(\"name\")`](REFERENCE.md#propertyabsentornull), it may often be simpler to check the properties\nthat **are** present, and then use the [`count`](REFERENCE.md#count) function to check that only that number of\nproperties are present.\n\n### Check for Member of Collection\n\nYou can check a value as being a member of a `Collection`.\nFor example:\n```kotlin\n    property(\"quality\", setOf(\"good\", \"bad\"))\n```\nThis test will succeed if the value of the property is one of the members of the set.\n\nThe `Collection` must be of the appropriate type for the value being checked, and each of the functions `property`,\n`item` and `value` has an overloaded version that takes a `Collection`.\n\n### Check for Value in Range\n\nYou can also check a value as being included in a range (`IntRange`, `LongRange` or `ClosedRange`).\nFor example:\n```kotlin\n    property(\"number\", 1000..9999)\n```\n\nAs with `Collection`, the range must be of the appropriate type, and each of the functions `property`, `item` and\n`value` has an overloaded version that takes a range.\n\n### Check for String Length\n\nThe [`length`](REFERENCE.md#length) function is available to check the length of a string.\nIf, for example, you expect a string to contain between 5 and 20 characters, but you don't need to check the exact\ncontents, you can specify:\n```kotlin\n    property(\"name\", length(5..20))\n```\nThe length may be specified as an integer value or an `IntRange`.\n\n### Check against `Regex`\n\nIt is also possible to check a string against a `Regex`, for example:\n```kotlin\n    property(\"name\", Regex(\"^[A-Za-z]+$\"))\n```\n\n### Exhaustive Checks\n\nTo confirm that all properties of an object or all items in an array are tested, the tests may be enclosed in an\n[`exhaustive`](REFERENCE.md#exhaustive) block, for example:\n```kotlin\n    propertyIsObject(\"address\") {\n        exhaustive {\n            property(\"number\", 27)\n            property(\"streetName\", \"23rd\")\n            property(\"streetType\", \"St\")\n        }\n    }\n```\nThis will cause an error to be reported if the object contains other properties in addition to those tested.\n\nAn `exhaustive` block can also check that all items in an array have been tested.\nThis can be particularly useful when paired with the [`anyItem`](REFERENCE.md#anyitem) test, for example:\n```kotlin\n    propertyIsArray(\"members\") {\n        exhaustive {\n            anyItem(\"Tom\")\n            anyItem(\"Dick\")\n            anyItem(\"Harry\")\n        }\n    }\n```\nThis tests that the array at `members` contains the items `\"Tom\"`, `\"Dick\"` and `\"Harry\"` in any order, and no other\nentries.\n\n### Multiple Possibilities\n\nYou can also check for a value matching one of a number of possibilities.\nThe [`oneOf`](REFERENCE.md#oneof) function takes any number of lambdas (as `vararg` parameters) and executes them in\nturn until it finds one that matches.\n```kotlin\n    property(\"elapsedTime\") {\n        oneOf(isDuration, isInteger)\n    }\n```\n\nTo simplify the use of lambdas in the `oneOf` list, the [`test`](REFERENCE.md#test) function creates a lambda\nrepresenting any of the available types of test:\n```kotlin\n    property(\"response\") {\n        oneOf(test(null), test(setOf(\"YES\", \"NO\")))\n    }\n```\n\nOf course, the full lambda syntax can be used to describe complex combinations.\nIn the following case, the JSON string may be either `{\"data\":27}` or `{\"error\":nnn}`, where _nnn_ is a number between\n0 and 999.\n```kotlin\n    json shouldMatchJSON {\n        oneOf({\n            property(\"data\", 27)\n        },{\n            property(\"error\", 0..999)\n        })\n    }\n```\n\n### Shared Tests\n\nIt is often useful to be able to share tests; for example, the same address may appear multiple times in a JSON Object.\nIf a function is written as an extension function on `JSONExpect`, it may be called wherever needed in the tests.\n```kotlin\n    fun JSONExpect.checkAddress() {\n        property(\"line1\", isNonBlankString)\n        property(\"line2\", isNonBlankString)\n        property(\"postcode\", postcodeRegex)\n    }\n```\nThen, in the tests:\n```kotlin\n        property(\"address\") {\n            checkAddress()\n        }\n```\n\n### Simple Tests\n\nWhen the set of tests to be applied to a JSON string is very simple, it may be more convenient to express them as a\ntarget JSON string:\n```kotlin\n    result shouldMatchJSON \"\"\"{\"number\":27,\"name\":\"George\"}\"\"\"\n```\nThis is exactly equivalent to:\n```kotlin\n    result shouldMatchJSON {\n        property(\"number\", 27)\n        property(\"name\", \"George\")\n        count(2)\n    }\n```\nBoth the string to be tested and the target string will be parsed into an internal form, so differences in whitespace or\nproperty order will not be significant.\nAnd while the DSL syntax has the advantage that errors will be reported against specific lines in the set of tests, the\ntarget string form will still give detailed error messages including the location in the JSON structure.\n\n### Custom Tests\n\nIn any of the tests that take a lambda parameter, the lambda is not restricted to the functions provided by the library;\nthe full power of Kotlin is available to create tests of any complexity.\n\nThe \u0026ldquo;receiver\u0026rdquo; for the lambda is an object describing the current node in the JSON structure, and the value\nis available as a `val` named\n[`node`](REFERENCE.md#node-nodeasstring-nodeasint-nodeaslong-nodeasdecimal-nodeasboolean-nodeasobject-nodeasarray).\nThe type of `node` is `JSONValue?`; [`JSONValue`](https://github.com/pwall567/kjson-core#jsonvalue) is a sealed\ninterface, and the implementing classes represent the JSON data types:\n\n- [`JSONString`](https://github.com/pwall567/kjson-core#jsonstring) \u0026ndash; a string value\n- [`JSONInt`](https://github.com/pwall567/kjson-core#jsonint) \u0026ndash; a number value that fits in a 32-bit signed\n  integer\n- [`JSONLong`](https://github.com/pwall567/kjson-core#jsonlong) \u0026ndash; a number value that fits in a 64-bit signed\n  integer\n- [`JSONDecimal`](https://github.com/pwall567/kjson-core#jsondecimal) \u0026ndash; any number value, including non-integer\n  (uses `BigDecimal` internally)\n- [`JSONBoolean`](https://github.com/pwall567/kjson-core#jsonboolean) \u0026ndash; a boolean value\n- [`JSONArray`](https://github.com/pwall567/kjson-core#jsonarray) \u0026ndash; an array\n- [`JSONObject`](https://github.com/pwall567/kjson-core#jsonobject) \u0026ndash; an object\n\nThere are also conversion functions, each of which takes the form of a `val` with a custom accessor.\nThese accessors either return the node in the form requested, or throw an `AssertionError` with a detailed error\nmessage.\n\n| Accessor        | Type                                                |\n|-----------------|-----------------------------------------------------|\n| `nodeAsString`  | `String`                                            |\n| `nodeAsInt`     | `Int`                                               |\n| `nodeAsLong`    | `Long`                                              |\n| `nodeAsDecimal` | `BigDecimal`                                        |\n| `nodeAsBoolean` | `Boolean`                                           |\n| `nodeAsArray`   | `JSONArray` (implements `List\u003cJSONValue?\u003e`)         |\n| `nodeAsObject`  | `JSONObject` (implements `Map\u003cString, JSONValue?\u003e`) |\n\nTo report errors, the [`error`](REFERENCE.md#error) function will create an `AssertionError` with the message provided,\nprepending the JSON pointer location for the current node in the JSON.\nThe [`showNode`](REFERENCE.md#shownode) function can be used to display the actual node value in the error message.\n\nExample:\n```kotlin\n    jsonString shouldMatchJSON {\n        property(\"abc\") {\n            if (nodeAsInt.rem(3) != 0)\n                error(\"Value not divisible by 3 - ${showNode()}\")\n        }\n    }\n```\n\n### Spring Framework\n\nMany users will wish to use `kjson-test` in conjunction with the\n[Spring Framework](https://spring.io/projects/spring-framework).\nA suggestion for simplifying some forms of Spring testing is included in the [Spring and `kjson-test`](SPRING.md) guide.\n\n\n## Dependency Specification\n\nThe latest version of the library is 5.1, and it may be obtained from the Maven Central repository.\n(The following dependency declarations assume that the library will be included for test purposes; this is\nexpected to be its principal use.)\n\n### Maven\n```xml\n    \u003cdependency\u003e\n      \u003cgroupId\u003eio.kjson\u003c/groupId\u003e\n      \u003cartifactId\u003ekjson-test\u003c/artifactId\u003e\n      \u003cversion\u003e5.1\u003c/version\u003e\n      \u003cscope\u003etest\u003c/scope\u003e\n    \u003c/dependency\u003e\n```\n### Gradle\n```groovy\n    testImplementation 'io.kjson:kjson-test:5.1'\n```\n### Gradle (kts)\n```kotlin\n    testImplementation(\"io.kjson:kjson-test:5.1\")\n```\n\nPeter Wall\n\n2025-06-24\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpwall567%2Fkjson-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpwall567%2Fkjson-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpwall567%2Fkjson-test/lists"}