{"id":22006350,"url":"https://github.com/a-sit-plus/jsonpath4k","last_synced_at":"2025-05-05T22:09:42.342Z","repository":{"id":238576829,"uuid":"790833353","full_name":"a-sit-plus/jsonpath4k","owner":"a-sit-plus","description":"Kotlin Multiplatform RFC9535 JSONPath Library","archived":false,"fork":false,"pushed_at":"2025-03-04T17:58:23.000Z","size":424,"stargazers_count":19,"open_issues_count":1,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-05-05T22:09:30.576Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://a-sit-plus.github.io/jsonpath4k/","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/a-sit-plus.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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}},"created_at":"2024-04-23T16:02:44.000Z","updated_at":"2025-03-04T17:56:41.000Z","dependencies_parsed_at":"2024-08-02T12:45:22.856Z","dependency_job_id":"6dc77d9e-e84c-4f15-862e-0eaef438ca83","html_url":"https://github.com/a-sit-plus/jsonpath4k","commit_stats":null,"previous_names":["a-sit-plus/jsonpath","a-sit-plus/jsonpath4k"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-sit-plus%2Fjsonpath4k","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-sit-plus%2Fjsonpath4k/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-sit-plus%2Fjsonpath4k/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-sit-plus%2Fjsonpath4k/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/a-sit-plus","download_url":"https://codeload.github.com/a-sit-plus/jsonpath4k/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252584329,"owners_count":21771945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-30T01:11:44.262Z","updated_at":"2025-05-05T22:09:42.324Z","avatar_url":"https://github.com/a-sit-plus.png","language":"Kotlin","funding_links":[],"categories":["JSON"],"sub_categories":["语音合成"],"readme":"\u003cdiv align=\"center\"\u003e\n\n# ![JsonPath4K](jsonpath4k.png)\n\n\u003c/div\u003e\n\n\n[![A-SIT Plus Official](https://img.shields.io/badge/A--SIT_Plus-official-005b79?logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNDMuNzYyODYgMTg0LjgxOTk5Ij48ZGVmcz48Y2xpcFBhdGggaWQ9ImEiIGNsaXBQYXRoVW5pdHM9InVzZXJTcGFjZU9uVXNlIj48cGF0aCBkPSJNMCA1OTUuMjhoODQxLjg5VjBIMFoiLz48L2NsaXBQYXRoPjwvZGVmcz48ZyBjbGlwLXBhdGg9InVybCgjYSkiIHRyYW5zZm9ybT0ibWF0cml4KDEuMzMzMzMzMyAwIDAgLTEuMzMzMzMzMyAtNDgyLjI1IDUxNy41MykiPjxwYXRoIGZpbGw9IiMwMDViNzkiIGQ9Ik00MTUuNjcgMjQ5LjUzYy03LjE1LjA4LTEzLjk0IDEtMjAuMTcgM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wIDAgMS04LjI0IDkuNTggMzUuMDEgMzUuMDEgMCAwIDEtMTEuOTYgNS41NyA1NS4yNSA1NS4yNSAwIDAgMS0xMi41NyAxLjc3Yy00LjMyLS4xLTguNjEtLjcxLTEyLjc1LTEuOGEzNS4wNSAzNS4wNSAwIDAgMS0xMS45Ni01LjU3IDI4LjUyIDI4LjUyIDAgMCAxLTguMjMtOS41OGMtMS44Ni0zLjQ0LTIuOS03LjU1LTMuMDktMTIuMmwtLjAxLTcuNDdoODkuMTZhLjcuNyAwIDAgMCAuNy0uNzJ2LTM5LjVjLS4xLTcuNjUtMS41OC0xNC40LTQuMzgtMjAuMDZhNDAuNCA0MC40IDAgMCAwLTExLjk1LTE0LjU2IDUyLjM3IDUyLjM3IDAgMCAwLTE3LjQ4LTguNDcgNzcuNTYgNzcuNTYgMCAwIDAtMjAuMDEtMi43N1oiLz48cGF0aCBmaWxsPSIjY2U0OTJlIiBkPSJNNDE5LjM4IDI4MC42M2gtNy41N2EuNy43IDAgMCAwLS43MS43MXYxNS40MmE4LjE3IDguMTcgMCAwIDAtMy43OCA2LjkgOC4yOCA4LjI4IDAgMCAwIDE2LjU0IDAgOC4yOSA4LjI5IDAgMCAwLTMuNzYtNi45di0xNS40MmEuNy43IDAgMCAwLS43Mi0uNzEiLz48L2c%2BPC9zdmc%2B\u0026logoColor=white\u0026labelColor=white)](https://a-sit-plus.github.io)\n[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-brightgreen.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0)\n[![Kotlin](https://img.shields.io/badge/kotlin-multiplatform-orange.svg?logo=kotlin)](http://kotlinlang.org)\n[![Kotlin](https://img.shields.io/badge/kotlin-2.0.20-blue.svg?logo=kotlin)](http://kotlinlang.org)\n[![Java](https://img.shields.io/badge/java-17+-blue.svg?logo=OPENJDK)](https://www.oracle.com/java/technologies/downloads/#java17)\n[![Maven Central](https://img.shields.io/maven-central/v/at.asitplus/jsonpath4k)](https://mvnrepository.com/artifact/at.asitplus/jsonpath4k/)\n\nThis is a Kotlin Multiplatform Library for using Json Paths as specified in [RFC9535](https://datatracker.ietf.org/doc/rfc9535).\n\n## Architecture\n\nThis library was built for [Kotlin Multiplatform](https://kotlinlang.org/docs/multiplatform.html) targeting JVM/Android and iOS. Other targets might work, but are\nnot tested or even built.\n\nNotable features for multiplatform are:\n\n- Use of [Napier](https://github.com/AAkira/Napier) as the logging framework for the default compiler instance\n- Use of [Kotest](https://kotest.io/) for unit tests\n- Use of [kotlinx-serialization](https://github.com/Kotlin/kotlinx.serialization) for serialization from/to JSON and to have JsonElement as evaluation target for JsonPathQuery\n\n## Using the Library\n1. Add JsonPath4K as a dependency in your project (`at.situplus:jsonpath4k:$version`)\n2. Use the `JsonPath` constructor for compiling JSONPath query expressions.\n3. Invoke the method `JsonPath.query` to select nodes satisfying the JsonPath query expression from a `JsonElement`.\n4. A `nodeList` containing both the selected values and their normalized paths is returned.\n\nIn general, things are called what they are. Most prominently, _JsonPath4K_ is not used anywhere in code – even though this\nproject is called JsonPath4K, it provides _JSONPath_ functionality for Kotlin Multiplatform, \nnot _JsonPath4K_ functionality because there is no such thing.\n\n```kotlin\nval jsonElement = buildJsonArray { add(0) }\n\nval jsonPathQueryExpression = \"$[0]\"\nval jsonPath = JsonPath(jsonPathQueryExpression)\n\nval nodeList = jsonPath.query(jsonElement)\nval jsonValue = nodeList[0].value.jsonPrimitive\nval normalizedPath = nodeList[0].normalizedJsonPath\n```\n\n## Function extensions\nThis library supports the function extensions specified in [RFC9535](https://www.rfc-editor.org/rfc/rfc9535.html#name-function-extensions) by default. \n\n### Custom function extensions\nCustom function extensions can be added using `JsonPathDependencyManager.functionExtensionRepository.addExtension`:\n```kotlin\n// adding a logical type function extension with 1 parameter of type NodesType\nJsonPathDependencyManager.functionExtensionRepository.addExtension(\"foo\") {\n    JsonPathFunctionExtension.LogicalTypeFunctionExtension(\n        JsonPathFilterExpressionType.NodesType\n    ) {\n        true\n    }\n}\n\n// adding a value type function extension returning a JsonValue with 2 parameters of type ValueType\nJsonPathDependencyManager.functionExtensionRepository.addExtension(\"foo\") {\n    JsonPathFunctionExtension.ValueTypeFunctionExtension(\n        JsonPathFilterExpressionType.ValueType,\n        JsonPathFilterExpressionType.ValueType,\n    ) {\n        JsonPrimitive(\"\")\n    }\n}\n\n// adding a value type function extension returning the JsonValue with 2 parameters of type ValueType\nJsonPathDependencyManager.functionExtensionRepository.addExtension(\"foo\") {\n    JsonPathFunctionExtension.ValueTypeFunctionExtension(\n        JsonPathFilterExpressionType.ValueType,\n        JsonPathFilterExpressionType.ValueType,\n    ) {\n        JsonNull\n    }\n}\n\n// adding a value type function extension returning the special value `Nothing` with 2 parameters of type LogicalType\nJsonPathDependencyManager.functionExtensionRepository.addExtension(\"foo\") {\n    JsonPathFunctionExtension.ValueTypeFunctionExtension(\n        JsonPathFilterExpressionType.LogicalType,\n        JsonPathFilterExpressionType.LogicalType,\n    ) {\n        null\n    }\n}\n\n// adding a nodes type function extension with 2 parameters of type ValueType\nJsonPathDependencyManager.functionExtensionRepository.addExtension(\"foo\") {\n    JsonPathFunctionExtension.NodesTypeFunctionExtension(\n        JsonPathFilterExpressionType.ValueType,\n        JsonPathFilterExpressionType.ValueType,\n    ) {\n        listOf()\n    }\n}\n\n// adding a nodes type function extension with 2 parameters of type ValueType\nJsonPathDependencyManager.functionExtensionRepository.addExtension(\"foo\") {\n    JsonPathFunctionExtension.NodesTypeFunctionExtension(\n        JsonPathFilterExpressionType.ValueType,\n        JsonPathFilterExpressionType.ValueType,\n    ) {\n        listOf()\n    }\n}\n```\n\n### Removing Function extensions\nFunction extensions can be removed from the default repository by setting the value of `JsonPathDependencyManager.functionExtensionRepository` to a new repository.\n\nExisting functions can be preserved by exporting them using `JsonPathDependencyManager.functionExtensionRepository.export()` and selectively importing them into the new repository.\n\n\n\n### Testing custom function extensions\nIn order to test custom function extensions without polluting the default function extension repository, it is advised to make an export and use the resulting map to build a function extension retriever.\n\n```kotlin\nval testRetriever = JsonPathDependencyManager.functionExtensionRepository.export().plus(\n    \"foo\" to JsonPathFunctionExtension.LogicalTypeFunctionExtension(\n        JsonPathFilterExpressionType.ValueType,\n        JsonPathFilterExpressionType.ValueType,\n    ) {\n        true\n    }\n)\nval jsonPath = JsonPath(jsonPathStatement, functionExtensionRetriever = testRetriever::get)\n\n// select from a json element\njsonPath.query(buildJsonElement {})\n```\n\n## Error handeling\nThe default compiler uses Napier for reporting errors. \nIt is possible to implement a custom error listener by extending `AntlrJsonPathCompilerErrorListener` and setting a new default compiler:\n```kotlin\nJsonPathDependencyManager.compiler = AntlrJsonPathCompiler(\n    errorListener = object : AntlrJsonPathCompilerErrorListener {\n        //TODO: IMPLEMENT MEMBERS                                                            \n    },\n)\n```\n\n## Contributing\nExternal contributions are greatly appreciated!\nJust be sure to observe the contribution guidelines (see [CONTRIBUTING.md](CONTRIBUTING.md)).\n\n\n\u003cbr\u003e\n\n---\n\u003cp align=\"center\"\u003e\nThe Apache License does not apply to the logos, (including the A-SIT logo) and the project/module name(s), as these are the sole property of\nA-SIT/A-SIT Plus GmbH and may not be used in derivative works without explicit permission!\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa-sit-plus%2Fjsonpath4k","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa-sit-plus%2Fjsonpath4k","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa-sit-plus%2Fjsonpath4k/lists"}