Pricing Blog

How to update deep value in json tree

  • skiinberlin-1384974877202579468

    SkiinBerlin

    1 month ago

    I'm building a self referencing component where you can add sub objects indefinitley. I got it work! But the issue im having now is how to handle edits to the object. Lets say im a few levels in the json, and change a value. This level has no knowledge about its parents. So i try to send the data up, but sending the data up a level is on the child object, but that is the same component as the parent object. so aaaahh im really confused. here's what i have so far. i tried with events and stuff but still wasnt able to get it working: https://editor.nordcraft.com/projects/sapphire_bossk_gastric_panda/branches/start/components&sourceid=chrome&ie=UTF-8&sei=_w9TaNTuFPrAi-gP9ZOY8Qg

    The end goal is that the json will be a value in a table. so any change done visually, will get sent to the db and then be reflected in the builder.

    Thanks!
  • mvvdv-1385084785818603611

    MVvdV

    1 month ago

    you have to pass in the entire JSON tree again and use the Find, Get and Set functions to drill down into each level, so you work backwards, image is just and example.
    1385084785512153118-Screenshot_2025-06-19_at_12.31.01.png
  • andreasmoller-1385122110480977990

    Andreas Møller

    1 month ago

    Det can take an array as the second input for setting deep properties
  • skiinberlin-1385182340153606226

    SkiinBerlin

    1 month ago

    I dont understand...
    I find the the entire subobject (with its subobjects) and replace it somehow?
  • Tod-1385182341802098751

    Tod

    1 month ago

    Great job @SkiinBerlin! Your contribution to the Nordcraft Community just made you advance to Community Level 1! 🌲
  • andreasmoller-1385208156929396746

    Andreas Møller

    1 month ago

    Say you have this object
    1385208156346519613-CleanShot_2025-06-19_at_12.42.302x.png
  • An I want to change Kaspers name property
  • 1385208375041851432-CleanShot_2025-06-19_at_12.43.162x.png
  • Now he is Super kasper
  • skiinberlin-1385331693195628585

    SkiinBerlin

    1 month ago

    I see... but i feel like my situation is different because the deep object has no knowledge of the full object, just it's values/properties. Imagine the Simple Json viewwer you built. How would you add the evility to edit values within that json viewer? if its a nested object.
  • it feels more complex, but maybe its just a lack of understanding
  • mvvdv-1385892084434604115

    MVvdV

    1 month ago

    you can get another mechanic to 'find' the object you need to change, you can get the item from an event like currentTarget from mouse event or you can get element by ID and use its properties to find itself in your JSON structure.