I wrote a method to concatenate JSON values.
def mergeSales(storeJValue: JValue): String = {
val salesJValue: JValue = parse(rawJson)
val store = compact(render(storeJValue))
val sales = compact(render(salesJValue))
val mergedSales: String = s"""{"store":$store,"sales":$sales}"""
mergedSales
}
As a result I'm getting strings like this, a store with an array of corresponding sales:
{"store":{"store_id":"01","name":"Store_1"}, "sales":[{"saleId": 10, "name": "New name1", "saleType": "New Type1"}, {"saleId": 20, "name": "Some name1", "saleType": "SomeType5"}, {"saleId": 30, "name": "Some name3", "saleType": "SomeType3"}]}
How should I parse it to get a list of records where the same store is mapped to each sale from the array? I want it to look like this:
{"store":{"store_id":"01","name":"Store_1"}, "sale":{"saleId": 10, "name": "New name1", "saleType": "New Type1"}}
{"store":{"store_id":"01","name":"Store_1"}, "sale":{"saleId": 20, "name": "New name2", "saleType": "New Type2"}}
{"store":{"store_id":"01","name":"Store_1"}, "sale":{"saleId": 30, "name": "Some name3", "saleType": "SomeType3"}}
Sales have a huge amount of fields in reality, so creating a case class will be rather complex.