How to convert String value to Object

shaik_irfan
Tera Guru

Hi,

 

I have String value which i want to convert as Object.

 

string =  "user firstname" : "first name", "user lastname" :"last name",  "user fullname" :"full name"

 

I want to convert this string into an object. Challenge is we may lot many values in String field which we are not sure so how to set them into 1 object dynamically

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Shaik,

that seems to me like a json object;

store that in json rather than string

var jsonObj = {"user firstname":"first name","user lastname":"last name","user fullname":"full name"};

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Ankur,

 

Actualy we have a field that contains values as shown below, for JSON i think we need to start with '{' & end with '}' but the input we get the as shown below:

 

string =  "user firstname" : "first name", "user lastname" :"last name",  "user fullname" :"full name"

 

Hi,

So then add it in? How are you getting this information? You can script to add that to the front and end.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Shaik,

so you can easily add starting and ending curly bracket and rest part is already having json format

what is the purpose of that field? is it just used for storing

if yes then you can have name value type of field which will internally store data as json string

https://docs.servicenow.com/bundle/london-platform-administration/page/administer/reference-pages/re...

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader