Created
March 25, 2014 11:14
-
-
Save bennadel/9759595 to your computer and use it in GitHub Desktop.
JSON Files As Temporary File Storage In ColdFusion Applications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- | |
Get the full file path to the directory in which we are | |
storing our serialized JSON data files. | |
---> | |
<cfset dataDirectory = getDirectoryFromPath( | |
getCurrentTemplatePath() | |
) /> | |
<!--- Create a basic ColdFusion object. ---> | |
<cfset girl = { | |
name = "Joanna", | |
hair = "Brunette", | |
bestAttributes = [ | |
"Smile", | |
"Legs" | |
] | |
} /> | |
<!--- | |
Serialize the ColdFusion data object into a JSON string | |
and write it to disk. | |
---> | |
<cfset fileWrite( | |
"#dataDirectory#data.json", | |
serializeJSON( girl ) | |
) /> | |
<!--- | |
Read in serialized JSON string a deserialized it back into | |
a ColdFusion data object. | |
---> | |
<cfset girlFromJSON = deserializeJSON( | |
fileRead( "#dataDirectory#data.json" ) | |
) /> | |
<!--- Output the ColdFusion data object created JSON. ---> | |
<cfdump | |
var="#girlFromJSON#" | |
label="JSON to ColdFusion" | |
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- | |
Get the full file path to the directory in which we are | |
storing our serialized JSON data files. | |
---> | |
<cfset dataDirectory = getDirectoryFromPath( | |
getCurrentTemplatePath() | |
) /> | |
<!--- Create a basic ColdFusion object. ---> | |
<cfset girl = { | |
name = "Joanna", | |
hair = "Brunette", | |
bestAttributes = [ | |
"Smile", | |
"Legs" | |
] | |
} /> | |
<!--- Serailize the ColdFusion object into a WDDX string. ---> | |
<cfwddx | |
action="cfml2wddx" | |
input="#girl#" | |
output="girlWDDX" | |
/> | |
<!--- Write the WDDX data to disk. ---> | |
<cfset fileWrite( | |
"#dataDirectory#data.xml", | |
girlWDDX | |
) /> | |
<!--- | |
Read in serialized WDDX string a deserialized it back into | |
a ColdFusion data object. | |
---> | |
<cfwddx | |
action="wddx2cfml" | |
input="#fileRead( '#dataDirectory#data.xml' )#" | |
output="girlFromWDDX" | |
/> | |
<!--- Output the ColdFusion data object created JSON. ---> | |
<cfdump | |
var="#girlFromWDDX#" | |
label="WDDX to ColdFusion" | |
/> |
@OneGrumpyBunny I'm glad this helpful; but, looking at the content of these gists, I wanted to apologize for some of the crude-ish references. I recently tried to clean-up really old (and younger me) references like this; but, it seems that the Gists live on. For a deeper explanation, take a look at: https://www.bennadel.com/blog/3791-as-a-man-i-can-be-a-better-example-than-i-have-been.htm
That said, I am bullish on the use of JSON as a storage mechanism. Have you looked at "NDJSON" or "Newline Delimited JSON". It can be really helpful on massive files, where each line is its own isolated JSON payload: https://www.bennadel.com/blog/3668-parsing-and-serializing-large-datasets-using-newline-delimited-json-in-lucee-5-3-2-77.htm
Thank you for the warning. I'm working on a project with a unique need. I'm
creating a temporary data storage that content owners can interact with
which can then be pulled in to a CMS (Cornerstone) as an import.
This prevents the content owners from having to interact with a highly
customized code-dependent page on the CMS. What I needed was to stringify
an object created from form input. JSON is the perfect format to bridge
raw data between two incompatible systems. 😀
I haven't used NDJSON I'll check that out. Thanks for the tip!
…On Wed, May 27, 2020, 8:38 AM Ben Nadel ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
@OneGrumpyBunny <https://github.com/OneGrumpyBunny> I'm glad this
helpful; but, looking at the content of these gists, I wanted to apologize
for some of the crude-ish references. I recently tried to clean-up really
old (and younger me) references like this; but, it seems that the Gists
live on. For a deeper explanation, take a look at:
https://www.bennadel.com/blog/3791-as-a-man-i-can-be-a-better-example-than-i-have-been.htm
That said, I am bullish on the use of JSON as a storage mechanism. Have
you looked at "NDJSON" or "Newline Delimited JSON". It can be really
helpful on massive files, where each line is its own isolated JSON payload:
https://www.bennadel.com/blog/3668-parsing-and-serializing-large-datasets-using-newline-delimited-json-in-lucee-5-3-2-77.htm
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://gist.github.com/9759595#gistcomment-3319851>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADAOT7A3WRJB6XBAO6IZH73RTUCUXANCNFSM4NMCS4WQ>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nicely done. Exactly what I needed.