Copy link to clipboard
Copied
Is there a specific way to open and read a json file other than using cfhttp tag?
<cfset koGroupsJSON = fileRead("https://devbox.mysite.com/search/KOGroups.json")>
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
It's a local file. I was afraid that cfhttp would not be as safe as cffile.
Thanks!
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Again, if it's a local file, why are you using CFHTTP? Just use CFFILE with the "read" action to read the contents into a variable, then use deserializeJSON on that variable.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
<cfset koGroupsJSON = fileRead("https://devbox.mysite.com/search/KOGroups.json")>
Copy link to clipboard
Copied
Okay, that works and many thanks for that but since both cffile and cfhttp use the "https" path, is there any security advantage of one over the other?
Copy link to clipboard
Copied
That question only has theoretical interest. Cffile and cfhttp are making the calls within Coldfusion, so they are both secure. (In the sense that, in either case, an outsider will be unable to access the data)
Copy link to clipboard
Copied
Thanks, BKBK!
Copy link to clipboard
Copied
Okay, something odd happened. It's now giving me this error:
Error in custom script module
(/devsite/customcf/knowledge/articleDetail.cfm)
An error occurred when performing a file operation exists on file /search/KOGroups.json.
The cause of this exception was: org.apache.commons.vfs2.FileSystemException: Could not determine the type of file "https://devbox.mysite.com/search/KOGroups.json"
This is my code:
<cfset groupData = deserializeJSON(fileread("https://devbox.mysite.com/search/KOGroups.json")) />
Copy link to clipboard
Copied
Okay, some help from my other thread, I found that using expandPath('fileName') will generate the absolute path and that seems to work. So for my future reference, this is the code that works:
<cfset groupData = deserializeJSON(fileread(\\commonspotshare.mysite.com\commonspot$\DEVELOPMENT\devbox.mysite.com\kb\article\KOGroups.json)) />