create json objects in collection

Is it possible to place input in a collection field where the content is a json object or gets read as such?
So for example inputting something like { “key1”:“value1”,“key2”:“value2”, … } ?

My goal is to use a json object/dict and connect it to a table on a dynamic page.

For now what I’ve managed to do is place a string in a collection field, and then using code on the main page to read that element and translate the string into an object, but I would like to already have the object key:value in my collection so that I can read it directly.

I saw the API page on setFieldValue() which is the closest thing I could find, but that means that all collection data will need to be iterated over every time the page loads which isn’t what I want or very efficient…

Any suggestions?

Hi Yafim,
I’m not sure I completely understand, but you can either save the entire object as a single field and use code to parse it yourself. However if you then wish to update a single value you will have to construct the full object and update all the object text.
Or, you could use wixData.save and insert/update multiple values at once.

You could then use a dataset on your page to easily connect to your collection, filter values, and connect the values to a table - without a single line of code.
check out these articles:

Let me know if that helped you with your goal.

Hi Omer,

I’ll try to explain again better. The links you sent are the non-code way to manage data, which I am familiar with, and I’ve already manipulated the field string with code as you suggest and rebuilt it into an object.

My goal is this:

Given an field in a collection, how can I read it into a table as if it is a key:value object?

For example if I have a text field with a string “color:red,width:10m,height:20m”, how can I read that into a table that directly reads the data into rows that say “color” “width” and “height” and values of those rows that say “red”, “10m” and “20m” ?

If I manipulate the string as a string which I parse, as you say and as I’ve already done, then it means that every time the page loads, this manipulation happens all over again, which means that if I have 100 fields this will be a very slow and inefficient way to process data… do you understand my meaning?