We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
def print_mongo_paths(json_object, current_path=""): if isinstance(json_object, dict): for key, value in json_object.items(): new_path = f"{current_path}.{key}" if current_path else key print_mongo_paths(value, new_path) elif isinstance(json_object, list): for i, item in enumerate(json_object): new_path = f"{current_path}.{i}" if current_path else str(i) print_mongo_paths(item, new_path) else: print(current_path) # Example JSON object example_json = { "file": [ { "extraction": { "signature": { "extraction": [ { "signature": { "extraction": { "normalized_value": "example_value" } } } ] } } } ] } # Print paths in MongoDB query format print_mongo_paths(example_json)
The text was updated successfully, but these errors were encountered:
import play.api.libs.json.{JsObject, JsArray, JsValue} object JsonPathPrinter { def printMongoPaths(json: JsValue, currentPath: String = ""): Unit = { json match { case obj: JsObject => obj.fields.foreach { case (key, value) => val newPath = if (currentPath.isEmpty) key else s"$currentPath.$key" printMongoPaths(value, newPath) } case arr: JsArray => arr.value.zipWithIndex.foreach { case (item, index) => val newPath = if (currentPath.isEmpty) index.toString else s"$currentPath.$index" printMongoPaths(item, newPath) } case _ => println(currentPath) } } def main(args: Array[String]): Unit = { // Example JSON object val exampleJson: JsValue = play.api.libs.json.Json.parse(""" |{ | "file": [ | { | "extraction": { | "signature": { | "extraction": [ | { | "signature": { | "extraction": { | "normalized_value": "example_value" | } | } | } | ] | } | } | } | ] |} """.stripMargin) // Print paths in MongoDB query format printMongoPaths(exampleJson) } }
Sorry, something went wrong.
No branches or pull requests
The text was updated successfully, but these errors were encountered: