- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2022 04:29 PM
Have a requirement to store some structured data in a field. Was thinking XML or JSON (with preference for JSON). I notice that ServiceNow has a a field type of JSON, but it is hidden from selection and the record is read only. So have the following questions
- has anyone used the JSON field type on custom fields? If yes -
- how did you create the column record with the correct type (e.g modified XML and imported it, used script to unhide the JSON type, etc)?
- any ramifications?
- If the JSON field type is unavailable - I assume a String field is the way to go.
- how do you manage JSON format validation?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2022 04:49 PM
Sample code.
var jsonObj = {"users":[{"name": "ozawa","user_id":"ozawa_h"}]};
// convert json object to string
var jsonStr = JSON.stringify(jsonObj);
gs.info(jsonStr);
// convert string to json object
var jsonObj2 = JSON.parse(jsonStr);
var users = jsonObj2.users;
for (var i=0; i<users.length; i++) {
gs.info(users[i].name);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2022 04:43 PM
Hi Steve,
I usually just JSON.stringify() the object and save it in a string field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2022 04:49 PM
Sample code.
var jsonObj = {"users":[{"name": "ozawa","user_id":"ozawa_h"}]};
// convert json object to string
var jsonStr = JSON.stringify(jsonObj);
gs.info(jsonStr);
// convert string to json object
var jsonObj2 = JSON.parse(jsonStr);
var users = jsonObj2.users;
for (var i=0; i<users.length; i++) {
gs.info(users[i].name);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2022 04:50 PM
FYI, information on using JSON field.