Hi, is it possible to output and also update individual elements of a JSON object using server connect functionality?
The JSON is stored in one column in a Postgres database and looks like this…
{"weight": 1.5, "price_exponent": 0, "count": 5, "volume": 0, "collect_weight": true, "collect_category": false, "weight_units": "Kg", "volume_units": "", "weight_si": 0, "volume_si": 0, "collect_count": true, "collect_volume": false, "collect_price": true, "range": 0, "rangevalue": -1, "name": "Danggit", "unit_price": 180, "total_price": 270, "price_currency": "PHP", "typeOfSupply": 3, "isDonation": false, "isPayment": true, "isRecordAfterTP": true}
I want to take each one of the name/value pairs and output into a standard web form and then provide the ability to update some or all of the data.
I can do this in SQL so figured there might be a way to do it using Server Connect.
Thanks.
Apple
July 19, 2022, 6:42pm
2
I’m guessing you could use dmx-repeat on the front-end to iterate over the keys and output a form field with the name attribute (dmx-bind:name="$key"
, don’t know if that specific syntax works)
I don’t know how to answer this, but can you check a similar topic of mine and see if it helps you?
{
"name": "George",
"country": "NL"
}
How can I literally Database Insert such JSON without actually going through the traditional Database Insert dialog and selecting the fields? It’s not feasible to manually build the Database Insert as the columns may vary over time and I’d rather just throw in the JSON representation. We’re talking about a lot of columns here (+50) and growing, so you can guess it’s not going to be easy to deal with changing Database Inserts to add/edit new fields i…
Thanks for the reply. I did see your earlier post - seems you were trying to do something similar.
I think the update could be done relatively simply in a custom query using…
UPDATE table
SET column_name ->> 'name' = 'value'
I’m going to try that anyway.
Just need to work out how to get the values into a form - your suggestion may help.
Thanks again!