0

Is there any way to load an external JSON file into the foundry or slate without it being modified and call it in the code sandbox?

I tried to upload a simple JSON file to try to call it inside the code sandbox, but every time I upload the file into the foundry it looks like this

Uploaded JSON

And inside this file there is nothing

Inside uploaded JSON

But in the original file, it has a content

content inside json

PS: Every time I uploaded the json file to the foundry I used the option - "Upload as a raw file without modifying the extension (recommended)"

option

1 Answers1

0

Here is an alternative, given it is not "uploading the file", strictly speaking.

You can paste the content of your JSON in a Slate's function, like :

    return [
        {
            "mykey": "myvalue"
        },
        {
            "mykey": "myvalue"
        }
    ]

The JSON will then be available in Slate by calling {{f_function}} if f_function is the name of your function.

For usage in Code-Sandbox, you can pass it via the interaction tab of Code-Sandbox.

Like:

    {
      "myjson": {{f_function}}
    }

You can then use SlateFunctions.getState in Code-Sandbox's JS to fetch the JSON, as the docs describe.

Another flavor: store your file in a Functions Code Repository and then call it from Slate which essentially leads to the same structure to pass it to CodeSandbox, but with {{ff_foundry_function}} instead of {{f_function}}.

ZettaP
  • 719
  • 7
  • 11
  • Yes, I tried to do that before I asked the question, but the library I'm using strictly requires a JSON file as parameter, but anyway I thank you for answering – Gabriel Gomes Feb 24 '23 at 11:38
  • What is the library ? Which function do you try to call ? Does it need a path to a file ? There might be some way to "emulate" the file (e.g. Blobs, etc.) – ZettaP Feb 24 '23 at 13:45
  • I am using a lib called d3.js and the function is d3.json(), I have been researching ways to bypass it, and will try with JSON.parse() – Gabriel Gomes Feb 24 '23 at 13:53
  • To what I see (https://stackoverflow.com/questions/35910649/how-to-load-a-json-object-instead-of-json-file) using .json() is not strictly needed. If you have a particular example in mind (which kind of graph are you trying to create?) it should be possible without referencing a file :) – ZettaP Feb 24 '23 at 14:46
  • Thanks man, thanks to the example you linked I made some changes in the code and the graphic appeared on the screen – Gabriel Gomes Feb 24 '23 at 15:33
  • Nice. Glad that I could help ! Good luck ! :D – ZettaP Feb 24 '23 at 16:14