on 10-12-2018 4:30 PM
Dear Experts,
JSON Structure field having double quotes with field names "JSON" to replace into field names JSON.
E.g:
Input Payload:
{
"structure":"JSON"
}
Output payload should come like this:
{
"Struture": JSON
}
My requirement is to remove the double quotes from target value actually i have tried the below groovy code it is not working
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.json.*
def Message processData(Message message) {
//Body
def body = message.getBody(String.class);
def jsonSlurper = new JsonSlurper()
def list = jsonSlurper.parseText(body)
list.each{
it.Structure=Integer.parseInt(it.get("Structure").toString().replace(" ",""));
}
def jsonOP = JsonOutput.toJson(list)
message.setBody(jsonOP)
return message;
}
Regards,
Naveen
I am getting same Error. DO we have any solution ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
naveen.arockiaraj hav you got this ans.. please share if yes ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Naveen,
Have you checked below thread which might help you.
Regards,
Sriprasad Shivaram Bhat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sriprasad,
Thanks for Replying.
I had gone through that thread i have used this below code for integer value it is working but string value it is not working:
My Requirement is:
Json Structure String to String
Input Payload:
{
"name":"naveen"
}
Output Payload:
{
"name": naveen
}
It is not working getting this error:
java.lang.Exception: java.lang.NumberFormatException: For input string: "naveen"@ line 13 in RemoveQuotes.groovy
as per the code it is working fine
JSON Strcuture String to Integer
{
"name":"1000"
}
Output Payload:
{
"name": 1000
}
but i need to remove that double quotes in char,Whether it is possible Please help me to complete my requirement.
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.json.*
def Message processData(Message message) {
//Body
def body = message.getBody(String.class);
def jsonSlurper = new JsonSlurper()
def list = jsonSlurper.parseText(body)
list.Root.each{
it.name=Integer.parseInt(it.get("name").toString().replace(" ",""));
}
def jsonOP = JsonOutput.toJson(list)
message.setBody(jsonOP)
return message;
}
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.