Json file input

Hi,

In my script I want to use data from a json file. I’ve tested pasting the json data in a text panel in grasshopper to see how the SDJSON components work, which all works perfectly! :slight_smile:
Now I would like to use a JSON file as an input in ShapeDiver, so the customer can upload their own file. I tried to use the SDTextfileInput component, but it only allows text/plain and text/csv, and it doesn’t seem compatible with the SDJSON components… Is there an other component I should be using? Am I missing something or is this simply not jet possible?

Thanks!

The text file input should work with JSON, you just need to store the JSON object in a text file (with extension .txt). That should make sure your file is imported as text in Grasshopper. Then try parsing this string using the ShapeDiverJSONParse component.
If the problem persists, please post more details about the error you are getting and the data you are using. Also try with this JSON file (right click - > save link as…), which is tested and works fine with this definition.

Thanks Mathieu. There must be something wrong with the link I was using, because I get the error “1. Could not read from URI.” . I tested your example files and those work perfect, so I guess I just have to fix the broken link. Thanks again!

Great, let me know how you store your files if you still have trouble with the links. Some online storage services don’t give full control over the mime types and can create problems. As far as we know, cloud computing services like AWS or Azure are the most reliable way to store your files. Dropbox has also reliably worked so far.

How would using dropbox work? That seems like it could be a very convenient method for me. I tried uploading your example txt file to dropbox and using the sharing link in grasshopper, but I get an error “Content-length missing”. What does that mean?

Sorry, I should have given more precisions about that :wink:
For dropbox, you need to give the “download” link, which ends with ?dl=1. If you use ?dl=0, it just gives a link to view the file on dropbox, which doesn’t work since we need to download it in the Grasshopper definition.

Perfect, it’s working now. Thanks for the help, Mathieu!

1 Like

Hi Mathieu,

I get the same “Content-length missing” message when i link from google drive,
do you know a similar method to obtain a downloadlink from google drive?

We didn’t try all solutions for hosting files, but as discussed above some of them just won’t work because of the way they store files. At the moment, Google Drive doesn’t provide flexible enough hosting options and it will not work with external geometry.

ok, that`s too bad

will try on of the others

thanks