help in spliting the query result

JPSS
Tera Contributor

I have an output as 

"68e911851b2be050ccbb6202b24bcbde","Not found"
 
or {"business_application":"68e911851b2be050ccbb6202b24bcbde","service_offering":"Not found"}
 
How can i convert it like var a=68e911851b2be050ccbb6202b24bcbde;
var b=NotFound;
3 REPLIES 3

Aqib4
Kilo Guru

Hi @JPSS,

To convert the given output into JavaScript variables `a` and `b`, you can use string manipulation techniques. Here's a simple way to achieve this using Javascript:// Assuming your output is stored in a variable called 'output'
var output = '"68e911851b2be050ccbb6202b24bcbde","Not found"';

// Remove the quotes and split the string by comma
var parts = output.replace(/"/g, "").split(",");

// Assign values to variables a and b
var a = parts[0];
var b = parts[1];

console.log("var a=" + a + ";");
console.log("var b=" + b + ";");
```

This will output:
var a=68e911851b2be050ccbb6202b24bcbde;
var b=Not found;

Make sure to adjust the `output` variable according to your actual input.
Please hit helpful and accept this as a solution if solves your queries.

Regards: Aqib

shyamkumar VK
Kilo Patron

@JPSS , Two ways you can do this , Store your values into an Array[] 

 

var a [‘example’,’split’]
var value1=a[0];
var value2=a[1];

 

If you want to use Split Functionality

You need to use below

var a = (‘example’,’spli’);

Var b = a.split(‘,’);

 

You can modify as per your need

 

Regards,

Shyamkumar

 

 

 

Please mark this as helpful and accept as a solution if this resolves your Ask.
Regards,

Shyamkumar

swathisarang98
Giga Sage
Giga Sage

Hi @JPSS ,

 

You can try below code to fetch jason values from key value pair,

 

var obj = {"business_application":"68e911851b2be050ccbb6202b24bcbde","service_offering":"Not found"};
var str =JSON.stringify(obj);
var parser = new JSONParser();
var result = parser.parse(str);
var a = result.business_application;
var b = result.service_offering;
//gs.print('a ' + a);
//gs.print('b ' + b);

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang