PricingBlog

Variable with JSON, connected to many inputs. How to edit just the binded value?

  • uunicode-1280435165369471068

    unicodes

    1 year ago

    I have many inputs connected to a variable JSON.

    Example 2 inputs first name and last name and the variable:

    {
    "last-name": "Doe",
    "first-name": "John"
    }

    Inputs are binded to the first and last name.

    When editing one input it change all the inputs in undefined. Why is not editing just the binded value (for example: first-name)?
  • tomthebigtree-1280437370398838805

    Tom Ireland

    1 year ago

    If you’re trying to change the value of a key/value pair in an object, binding the input to a variable will overwrite the whole object iirc. You’d need to use some logic to locate and set only the specific key/value pair in the object and leave the rest. I’d try to find the key/value pair by index or unique id if you capture that and then use Set to update the value. I do that a lot for different things. At work just now but can help out a bit later if you don’t find a solution.
  • uunicode-1280477816072310786

    unicodes

    1 year ago

    Thank you, Tom. It would be great if it worked natively. In this case, I would prefer to use variables for each input as it’s easier to manage. Thank you, and have a great day!
  • tomthebigtree-1280483297528643606

    Tom Ireland

    1 year ago

    Well, another option would be to continue to use variables for each input and then have your workflow just format the object after all changes. I assume you're sending this via API to a database or something?
  • uunicode-1280799518136471585

    unicodes

    1 year ago

    Yes, I'm using an API to save data on a database. Thank you Tom for you help 🙏