Skip to content

Commit

Permalink
Fix: Add JSON path parser dependency and function to validate the pac…
Browse files Browse the repository at this point in the history
…kage

Signed-off-by: George J Padayatti <george.padayatti@igrant.io>
  • Loading branch information
georgepadayatti committed Mar 9, 2024
1 parent 8a0c21d commit 58f27d1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ dependencies {
// Library dependencies
// JSON schema parser and validator
implementation("net.jimblackler.jsonschemafriend:core:0.12.3")
// JSON path parser
implementation("com.jayway.jsonpath:json-path:2.9.0")
}

// Apply a specific Java toolchain to ease working on different environments.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.github.decentraliseddataexchange.presentationexchangesdk

import net.jimblackler.jsonschemafriend.Schema;
import net.jimblackler.jsonschemafriend.SchemaStore;
import net.jimblackler.jsonschemafriend.Validator;
import com.jayway.jsonpath.JsonPath
import net.jimblackler.jsonschemafriend.Schema
import net.jimblackler.jsonschemafriend.SchemaStore
import net.jimblackler.jsonschemafriend.Validator


class PresentationExchange() {
private var schemaString: String? = null
Expand All @@ -25,4 +27,48 @@ class PresentationExchange() {
// Validate JSON based on the input, if failed will throw ValidationException
validator.validateJson(schema, input)
}

fun validateJsonPath() {
val json = """
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
""".trimIndent()
val authors = JsonPath.read<List<String>>(json, "$.store.book[*].author")
println(authors)
}
}

0 comments on commit 58f27d1

Please sign in to comment.