Skip to main content
2Charlie
Inspiring
March 7, 2016
Resuelto

How to open and read JSON file?

  • March 7, 2016
  • 1 respuesta
  • 14563 visualizaciones

Is there a specific way to open and read a json file other than using cfhttp tag?

    Este tema ha sido cerrado para respuestas.
    Mejor respuesta de BKBK

    As I've said above, I tried to use the <cfset kogroups = deserializeJSON(fileread(#KOGroups.json#)) /> but I'm not sure how to specify the path. It's unable to find the file. The actual location of the KOGroups.json is located in a shared folder and not on the IIS server. The path is "https://devbox.mysite.com/search/KOGroups.json but I'm not sure how to specify a relative path instead of a absolute path.


    <cfset koGroupsJSON = fileRead("https://devbox.mysite.com/search/KOGroups.json")>

    1 respuesta

    Carl Von Stetten
    Brainiac
    March 7, 2016

    Depends on where the file is located.  If you are pulling it from a remote site, then CFTTP seems reasonable.  If it's on a local drive or a network drive, then CFFILE should work.  And keep in mind there isn't anything special about a "JSON" file.  It's really just a text file, albeit in JavaScript Object Notation format in terms of structure.

    2Charlie
    Inspiring
    March 7, 2016

    It's a local file. I was afraid that cfhttp would not be as safe as cffile.

    Thanks!

    2Charlie
    Inspiring
    March 7, 2016

    Okay, so this is what I have in cftthp: <cfhttp url="https://devbox.mysite.com/search/KOGroups.json" method="get" timeout="15" />

    However, when I try the fileread I have this:

    <cfset kogroups = deserializeJSON(fileread(#KOGroups.json#)) />

    My question now is, how do specify the path in the fileread above?