score:1
Accepted answer
As you noticed if you use PlayJSON you can use Json Transformers
Updating a field would work like this:
val queryUpdater = (__ \ "definitions" \ 1 \ "SearchQuery" \ "query").json.update(
of[JsString].map {
case JsString(value) =>
val newValue: String = ... // calculate new value
JsString(newValue)
}
)
json.transform(queryUpdater)
If you needed to update all queries it would be more like:
val updateQuery = (__ \ "SearchQuery" \ "query").json.update(
of[JsString].map {
case JsString(value) =>
val newValue: String = ... // calculate new value
JsString(newValue)
}
)
val updateQueries = (__ \ "definitions").json.update(
of[JsArray].map {
case JsArray(arr) =>
JsArray(arr.map(_.transform(updateQuery)))
}
)
json.transform(updateQueries)
Source: stackoverflow.com
Related Query
- How to update nested JSON array in scala
- How to update a nested json using scala play framework?
- how to parse nested json array in scala
- How to add a json object in to a json array using scala play?
- Spark explode nested JSON with Array in Scala
- How to parse json list or array in scala for play framework 2.2
- How to convert nested JSON to map object in scala
- How to parse an array of json in scala play framework?
- How do I update a nested key of a JsObject in scala
- How to write a scala array into json file?
- Scala Spark How can I convert a column array[string] to a string with JSON array in it?
- In Scala how do you update a property of an object within an array of objects, the object being selected by the user
- Scala - How to Convert String Column to Array of Json
- How to create nested json using Apache Spark with Scala
- How to update each field in a list using Play json in Scala
- How to read json array in scala using the Play framework
- How to use different names when mapping JSON array to Scala object using combinators
- Scala Play Read: How to Flatten Json containing Array of arrays to model
- How to iterate through json array in scala
- Spark -Scala Nested array DF - How to update value based on condition without changing structure?
- Flatten nested json with array into single line dataframe in Apache Spark Scala
- how to update nested column's value of xml in spark scala dataframe
- How to read part of a nested json object in as a string in Scala
- how to update nested document inside array in elasticsearch
- How to update the duplicates in array in scala
- How to explode nested json array in data frame
- How to update a specific element in Immutable Array using Scala
- Scala Play: How to map JSON array structure to Case Class
- How to decode a nested json into a List[Object] using Circe in Scala
- How to split Array of Json DataFrame into multiple possible number of rows in Scala
More Query from same tag
- How to return Map in scala
- How to connect hive in scala program
- An Unexpected I/O exception with AsyncHttpClient while performing SSL requests
- SBT sub project access root project data (dependency version)
- Why should one prefer Option for error handling over exceptions in Scala?
- Contemporary way to make HoughLinesP work in JavaCV
- Cyclomatic complexity of scala
- Pattern matching in Scala with generic return type
- Scala: delay code bloc execution or cancel it
- What's the best way to change values of List objects?
- Optimize a piece of code that uses map action
- Spark RDD dynamic key generator
- fast power function in scala
- Tokenizing strings in a "String RDD" returning another RDD
- Bind extractor symbols multiple times in OR based pattern matching
- Pass a vector from Matlab to Scala Class
- Why is parallel aggregation not faster in spark?
- How do i perform conditional check using Gatling
- How to create an SBT Run configuration in IntelliJ IDEA 11 Community Edition?
- When anonfun$1 becomes anonfun$m1$1 (or vice versa) in Scala?
- StackOverflowError with Scala on IntelliJ
- How do I unit test closures with deeply nested anonymous functions in Scala?
- Avoid global state in Scala
- Proper way to access shared resource in Scala actors
- partial parameter list injection on play framework
- How to get the name of a column by its index?
- Difference between F[_] and F[T] In Scala when used in type constructors
- Overriding a trait and selftype
- are multiple features a good use case for logback markers?
- Getting a 302 http redirect location with Databinder-Dispatch