We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Read Json Data and put it into Variables

Home Forums Puzzles Read Json Data and put it into Variables

Tagged: 

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #39592
    Jakob Kolmanic
    Participant

    Hello,

    can someone please tell me how to read Values from a Json file ond save the values in variables?

    I have a json file like on the first picture and i want to import the values into my project and save the values into variables.

    Can someone please tell me the correct way?

    thank you!

    Attachments:
    You must be logged in to view attached files.
    #39607
    #39609
    jem
    Customer

    Hi Jokob,
    I have to do this on every project, so I will share the technique I use. Use the puzzles that Yuri pointed out, but here are a few tips.
    1. The “load data” puzzle is asynchronous. Don’t assume your data is loaded on the first frame. Use the “once ready do” slot to initiate whatever actions you need to perform.
    2. Check if a key is in a dictionary before using it. See puzzle screenshot. Catch the error and do something if the key is missing. Typos and other data errors happen.
    3. The dictionary data type in the puzzle system is implemented as a JS object. So if your JSON has nested JS objects, you will need to use the dictionary puzzles to pick through the JSON. See color values in the puzzle screenshot.
    json puzzles
    sphere image

    Attachments:
    You must be logged in to view attached files.

    Jeremy Wernick

    #39630
    karonte
    Customer

    thanks for your contribution!

    MR

    #39634
    Jakob Kolmanic
    Participant

    Thank you!

    #39674
    razvan8x
    Participant

    Hi Yuri,

    How can I read a subset of json listed? See the picture. I get false when I check the Ford string.

    For example the value of car1?

    {
    “name”:”John”,
    “age”:30,
    “cars”: {
    “car1″:”Ford”,
    “car2″:”BMW”,
    “car3″:”Fiat”
    }
    }

    Thank you!

    Attachments:
    You must be logged in to view attached files.
    #39681

    Hi,

    you should use nested get key puzzles to retrieve the inner value

    Chief 3D Verger | LinkedIn | Twitter

    #39838
    GLiFTeK
    Customer

    I think something similar to what Jem has shown should be added to the get JSON puzzle user manual entry.

    Just a thought.
    Powerful puzzle. Needs some elaborating I think. :good:

    #58365
    fred7
    Customer

    Hello,
    Thanks for the information!

    Unfortunately I can’t get it to work as I needed.

    Even if I simply try to read the loaded data I get an error in the console “Read JSON Puzzle: could not interpret data.” I don’t get it as the JSON I think is the same as in the example of Jem, just with strings.
    JSON
    could not interpret data error

    I added my current puzzles in the attachment, pretty sure it would not work that way.
    Puzzle

    What I want to archive:
    I have a JSON-File where IDs and corresponding RGB-color values are stored.

    In my parent HTML UI document there are buttons with the IDs of the JSON.

    When one of those buttons is clicked, I want to have the color of one material changed to the corresponding RGB-color value.

    How to do that?

    Thank You!

    I also did post my question in this topic, but I guess it makes more sense here:

    find text in specific row/column in list(table)

    Attachments:
    You must be logged in to view attached files.
    #58399

    @fred7

    It may be that the file was not actually loaded for some reason. You can try to print to console the loaded data and see if your JSON is there.

    Chief 3D Verger | LinkedIn | Twitter

    #58400
    fred7
    Customer

    @yuri

    Just sent you an email because of the “Read JSON Puzzle: could not interpret data.” error.

    I get this error also in an empty project, where I try to load the data.json file which is used by jem in his tutorial.

    Thank You for looking into this!

    #58403

    Yes I’ve seen the files and they are ok. The thing is that as of version 4.1, the load data puzzle automatically reads JSON, so the other puzzle read JSON must not be used.

    Chief 3D Verger | LinkedIn | Twitter

    #58408
    fred7
    Customer

    Thank you for the fast response and the helpful tip. Currently debugging and trying different puzzle/approaches to get my functionality working. Still struggling.

    Would be grateful for any input on how this would work.

    #58415
    kdv
    Participant

    read any .gltf file (in fact, it has the JSON format). see the result. does it work with your set of puzzles?

    read this https://www.soft8soft.com/topic/verge3d-4-1-1-maintenance-update/#post-55477

    Puzzles and JS coding. Fast and expensive.

    If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of the meaning at all.

    #58851
    jakob
    Customer

    Hello,
    I have the problem that after the update to 4.2 my puzzle logic for importing and reading a json-file via a rest API does not work anymore.
    The solution described above that you no longer need a “read json” puzzle I have already adapted.
    It all works when I load a local jason-file, but as soon as I want to load the json-file via a REST_API I get an error message (see photo). I think it has something to do with the response of the server.
    Would be very happy if someone has a solution.

    Link to the REST API with the json file:
    https://hook.eu1.make.com/qbgjk8a1f52jbwmv1qv95hz126c8j9dy

    Thanks a lot and best regards
    jakob

    Attachments:
    You must be logged in to view attached files.
Viewing 15 posts - 1 through 15 (of 18 total)
  • You must be logged in to reply to this topic.