Raj1
May 8, 2019, 8:34pm
1
This is my sample:
“clHd”: {
“adjudCode”: “64”,
“adjusNumr”: 20,
“fixCode”: “ABC”,
“assignedNumr”: “93612”,
Output
“clHd_adjudCode” :64,
“clHd_adjusNumr”: 20,
“clHd_fixCode”: “ABC”,
“clHd_assignedNumr”: “93612”
Request : I’m flattening the Json file and finally trying to write into the file
Below is transform the flatten and just print in the screen:
jsonParsed.transform(claimHeader).foreach(Json.stringify _ andThen println))
I have to write into the file(using scala) how will i write into above statement.
I tried this.But throw the error.Not enough declaration.
val s = new PrintWriter(“C:/Users/Rajesh/Desktop/Json_schema_output.txt”)
s.write(jsonParsed.transform(claimHeader).foreach(Json.stringify _ andThen println)
Please advise
What’s the exact error message? Could you post a small but complete code sample?
foreach returns Unit, and therefore it does not make sense to put an expression that ends with foreach as an argument to write.
Raj1
May 8, 2019, 9:14pm
3
object JsonExample {
def main(args: Array[String]) {
val clHder = (__ \ 'clHder).read[JsObject].flatMap(
.fields.foldLeft(( _ \ 'clHder).json.prune) {
case (acc, (k, v)) => acc andThen .json.update(
Reads.of[JsObject].map( + (s"clHder $k" -> v))
)
})
val source: String = Source.fromFile(“C:/Desktop/Json_schema.json”).getLines.mkString
val jsonParsed: JsValue = Json.parse(source)
How to use this in my below file write.I didn’t face any kind of error
println(jsonParsed.transform(clHd).foreach(Json.stringify _ andThen println))
val s = new PrintWriter(“C:/Desktop/Json_schema_output.txt”)
s.write()
s.close()
I have to write into the file.I don’t have idea how to mention the above
Raj1
May 9, 2019, 3:02am
4
I got it.Resolved my issue.Thanks for the hint.
Meenu
February 22, 2020, 1:02pm
5
Hi @Raj1 , I saw your question about Json parsing, I am also facing issues to parse the json, can you please help me? This is my question with Input and expected output. I don’t need any hard code in code as Tags are not fixed always.
INPUT JSON :
{
“Start”:{
“HInfo”:{
“HInfoID”:“ABCD1234”,
“SUType”:“OnStup”,
“SModel”:“Test”,
“Hostname”:“Dummy”,
“SType”:“Laptop”,
“Monitor”:{
“HInfoID”:“ABCD1234”,
“Index”:0,
“Type”:“Lenovo”,
“VSData”:“XYZVN”
},
“OS”:“MSW-07”,
“LRTime”:“2017-05-04”,
“Cables”:[
{
“HInfoID”:“ABCD1234”,
“Index”:0,
“Name”:“LC”,
“Status”:“Installed”
},
{
“HInfoID”:“ABCD1234”,
“Index”:1,
“Name”:“WLSwitch”,
“Status”:“Off”
},
{
“HInfoID”:“ABCD1234”,
“Index”:2,
“Name”:“WLAN”,
“Status”:“…
Meenu
February 22, 2020, 1:04pm
6
Hi @curoli , Can you please help me with this question? Please help.
INPUT JSON :
{
“Start”:{
“HInfo”:{
“HInfoID”:“ABCD1234”,
“SUType”:“OnStup”,
“SModel”:“Test”,
“Hostname”:“Dummy”,
“SType”:“Laptop”,
“Monitor”:{
“HInfoID”:“ABCD1234”,
“Index”:0,
“Type”:“Lenovo”,
“VSData”:“XYZVN”
},
“OS”:“MSW-07”,
“LRTime”:“2017-05-04”,
“Cables”:[
{
“HInfoID”:“ABCD1234”,
“Index”:0,
“Name”:“LC”,
“Status”:“Installed”
},
{
“HInfoID”:“ABCD1234”,
“Index”:1,
“Name”:“WLSwitch”,
“Status”:“Off”
},
{
“HInfoID”:“ABCD1234”,
“Index”:2,
“Name”:“WLAN”,
“Status”:“…