Updating a json object

Hey everyone

I have a Weweb project that I am working on. I am using Supabase for my backend. I have a table “fuel tanks” that has two columns, the ID column and tanks, which is a json object that holds the location, fuel type (diesel or petrol), capacity and current level

I would like to know how do i just update an element in the json object, for example, if i wanted to update the current_level for petrol?

When I change a value, the new value replaces the entire json object.

Unless you have a specific reason for using json, this should probably be another table and location and fuel type should be their own columns. Otherwise, you could edit the json on your frontend and send the entire object back.

You can do partial updates only on jsonb and as Micah said, using json is no bueno for regular things, especially performance wise, because you can’t set indexes on json (you can on jsonb) and the whole thing of accessing and querying json/jsonb is way slower than with normal columns. If you wanna work with json schemaless objects, I highly suggest using something like MongoDB or Firebase.

Okay, I’ll stick with the columns. I chose to use nocode/lowcode tools to make things easier for myself and not to complicate them, even though I don’t mind researching and learning other ways to do the same thing. thanks @Micah and @Broberto

1 Like

If you want, in my community we have quite some Supabase / SQL related resources. Brocode Land

1 Like