How to Create a Table with a JSON Field in ServiceNow?

Marium_07
Tera Contributor


Hi everyone,

I'm relatively new to ServiceNow and I'm trying to create a table with a JSON field in it. I need to store JSON data for some charts I'm planning to display on a portal page. Can someone guide me through the process of creating such a table and adding a JSON field to it?

I'd appreciate any help or pointers you can provide. Thank you in advance!

Best regards,
Marium.

 

1 ACCEPTED SOLUTION

Deepak Shaerma
Kilo Sage

ServiceNow doesn’t offer a specific “JSON” field type out of the box; however, you can use a String field type with a large enough character limit or a Large Text field to store JSON data.
Step 1: Create a New Table
1. Navigate to System Definition > Tables in the navigator menu.
2. Click on the “New” button to create a new table.
3. Fill in the necessary details:
Name: Give your table a meaningful name. This will be the label.
Table Name: This is auto-generated based on the Name but can be customized. It should be unique.
Extends Table (Optional): If you want this table to inherit fields from another table, you can select it here.
4. Click the “Create” button.



Step 2: Add a JSON Field
1. In the “Columns” section (where you land after creating the table), you can start adding fields.
2. Click on the “New” button to add a new field to your table.
3. For the JSON data field, select the Type “String” (for smaller JSON objects) or “Large Text” (recommended for larger JSON data) in the field properties.
4. In the Column label, enter a name like JSON Data or anything descriptive.
5. If you selected “String”, you might want to adjust the Maximum length as needed. For “Large Text”, the length is typically sufficient for storing JSON data.
6. After setting the properties, click on the “Submit” button.

Step 3: Use the JSON Field
- When creating or updating records in this table, in the JSON data field you’ve added, you can insert JSON formatted text. Ensure the text you’re entering is valid JSON to avoid issues when parsing it later.
- When you need to retrieve and use this JSON data in a portal widget or elsewhere, you can parse this JSON string back into an object using JSON.parse(yourJsonString) in client scripts or similar parsing methods in server-side scripts.


Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help us a lot.
- Keep Learning ‌‌
Thanks & Regards 
Deepak Sharma

View solution in original post

4 REPLIES 4

Deepak Shaerma
Kilo Sage

ServiceNow doesn’t offer a specific “JSON” field type out of the box; however, you can use a String field type with a large enough character limit or a Large Text field to store JSON data.
Step 1: Create a New Table
1. Navigate to System Definition > Tables in the navigator menu.
2. Click on the “New” button to create a new table.
3. Fill in the necessary details:
Name: Give your table a meaningful name. This will be the label.
Table Name: This is auto-generated based on the Name but can be customized. It should be unique.
Extends Table (Optional): If you want this table to inherit fields from another table, you can select it here.
4. Click the “Create” button.



Step 2: Add a JSON Field
1. In the “Columns” section (where you land after creating the table), you can start adding fields.
2. Click on the “New” button to add a new field to your table.
3. For the JSON data field, select the Type “String” (for smaller JSON objects) or “Large Text” (recommended for larger JSON data) in the field properties.
4. In the Column label, enter a name like JSON Data or anything descriptive.
5. If you selected “String”, you might want to adjust the Maximum length as needed. For “Large Text”, the length is typically sufficient for storing JSON data.
6. After setting the properties, click on the “Submit” button.

Step 3: Use the JSON Field
- When creating or updating records in this table, in the JSON data field you’ve added, you can insert JSON formatted text. Ensure the text you’re entering is valid JSON to avoid issues when parsing it later.
- When you need to retrieve and use this JSON data in a portal widget or elsewhere, you can parse this JSON string back into an object using JSON.parse(yourJsonString) in client scripts or similar parsing methods in server-side scripts.


Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help us a lot.
- Keep Learning ‌‌
Thanks & Regards 
Deepak Sharma

James Chun
Kilo Patron

Hi @Marium_07,

 

Although it's not a JSON, there is a Name-value pairs field type, e.g.

JamesChun_0-1711186700452.png

 

https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/administer/field-admini...

 

If that doesn't meet your requirements, you may just need to use a string field.

 

Cheers

Thank you so much for your assistance, I really appreciate your help with this.

 

Deepak Shaerma
Kilo Sage

Hi @Marium_07 
Note: Please Mark my response Helpful If this Helps you to understand. This will help both the community and me.
- Keep Learning ‌‌
Thanks & Regards 
Deepak Sharma