# Converting Table Data to JSON for SQL Server Data Element Input

**URL:** <https://forum.inductiveautomation.com/t/converting-table-data-to-json-for-sql-server-data-element-input/84418>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [January 17, 2024, 10:32pm UTC](https://forum.inductiveautomation.com/t/converting-table-data-to-json-for-sql-server-data-element-input/84418 "2024-01-17T22:32:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteveO](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steveo/32/55271_2.png) [@SteveO](https://forum.inductiveautomation.com/u/SteveO)\
**Post date:** [January 17, 2024, 10:32pm UTC](https://forum.inductiveautomation.com/t/converting-table-data-to-json-for-sql-server-data-element-input/84418/1 "2024-01-17T22:32:25Z")

</div>

The task is to convert unbound table data consisting of a single row of embedded Checkbox views into a JSON form to ultimately save into a SQL Server database.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/2/42f5698106c46c28a27d2ac3d2330218d7bdf70f.png)

The SavePreferences event script follows:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/0/d02958ba22c9aaf3ff9f26e48f1a1d1cb450f371.png)

The confounding error I receive follows:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/f/4f397933948811282a4133042f53b2699112e8db.png)

What is really troubling is that if I copy and review the data from the table it appears to be a perfect example of JSON formatted data:

{  
"Action": true,  
"ActionState": false,  
"ActionTimeStamp": false,  
"ActionType": false,  
"ActionUserEmail": false,  
"DateAssigned": true,  
"DateDue": true,  
"Id": false,  
"Notes": true,  
"Owner": true,  
"PctComplete": true,  
"Progress": true,  
"Segment": false,  
"Site": true,  
"Status": true  
}

I don't understand what is wrong here and deeply appreciate any insight to resolve the error.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 17, 2024, 10:45pm UTC](https://forum.inductiveautomation.com/t/converting-table-data-to-json-for-sql-server-data-element-input/84418/2 "2024-01-17T22:45:24Z")

</div>

Please see, [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831). It's generally a good idea to post code rather than pictures of code. That way we can copy and test it or modify it in our replies. Post a cropped screengrab too if you think the context is useful.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 17, 2024, 10:54pm UTC](https://forum.inductiveautomation.com/t/converting-table-data-to-json-for-sql-server-data-element-input/84418/3 "2024-01-17T22:54:07Z")

</div>

You have (papering over some minor technicalities) a JSON structure - specifically, a json array/list containing JSON objects _already_; your property tree.  
I don't see why you think you need to convert it into a PyDataset. You should be able to convert your Perspective property structure into a JSON string to insert in your query using `system.util.jsonEncode`.

---

<div class="post-metadata">

**Author:** ![SteveO](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steveo/32/55271_2.png) [@SteveO](https://forum.inductiveautomation.com/u/SteveO)\
**Post date:** [January 17, 2024, 11:30pm UTC](https://forum.inductiveautomation.com/t/converting-table-data-to-json-for-sql-server-data-element-input/84418/4 "2024-01-17T23:30:03Z")

</div>

Thank you for the insight... I pledge to improve my future posts.

---

<div class="post-metadata">

**Author:** ![SteveO](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steveo/32/55271_2.png) [@SteveO](https://forum.inductiveautomation.com/u/SteveO)\
**Post date:** [January 17, 2024, 11:31pm UTC](https://forum.inductiveautomation.com/t/converting-table-data-to-json-for-sql-server-data-element-input/84418/5 "2024-01-17T23:31:58Z")

</div>

Thank you for your proposed solution... implementing jsonEncode() it runs without error and now have an object to insert in the database.
