Shorthand for DESerializeJSON( SerializeJSON( obj ) )

I don’t know about you, but while I write code I often use this notation:

DESerializeJSON( SerializeJSON( obj ) )

which is also very long.

Can’t we create a shorthand for it?

A very simple
extractData()
?

there’s already obj.toJson() but the obj.deserializeJSON() is quite long

Nah, just write a function wrapper if you need to. extractData() isn’t even self explanatory

As an aside from your question, can I ask why you are deserializing an object that you just serialized? Is it possible you can just call duplicate() to achieve the same outcome?

Because i can see better the tree structure of the data parsed by cfdump.
With only SerializeJSON() I would only see a string.

It’s not so?

why not just dump(obj) then?

1 Like

I’m guessing there are booleans or other things that serialize changes so it’s useful to see after serializing?

Obj is an object.

Cfdump shows all methods and only at the end only the properties with the data inside. The html created is very large and difficult to read.


Still very long…

I just need the data. So:

image

I’m a little surprised that only I do this… :sweat_smile:

2 Likes

what does dump(obj.toString()) or dump(getMetaData(obj)) show?

Also, cfdump has the ability to hide functions as a property. cfdump( showudfs = false ). That might be helpful. Though, that might just collapse them, not remove them - I can’t remember off hand. But, I understand what you are trying to do.

2 Likes

dump(obj.toString())

Component [bean.Patient] has no function with name [toString]

dump( toString( bean ) ) ;

Can’t cast Component [Patient] to String

dump(getMetaData(obj))

All metadatas of object, but not data.

We use this on our objects when debugging to do something similar:
dump(obj.toStruct())

	<cffunction name="toStruct" access="public" returntype="struct" output="false" hint="Returns internal data. Use for debugging only.">
		<cfset local.instance = duplicate(variables) />
		<cfloop collection="#local.instance#" item="local.instanceKey">
			<cfif not isSimpleValue(local.instance[local.instanceKey])>
				<cfset structDelete(local.instance, local.instanceKey) />
			</cfif>
		</cfloop>
		<cfreturn local.instance />
	</cffunction>

1 Like

And stealing a page from your book, this would output the same thing:

	<cffunction name="toStruct" access="public" returntype="struct" output="false" hint="Returns internal data. Use for debugging only.">
		<cfreturn DESerializeJSON( SerializeJSON( this ) ) />
	</cffunction>
2 Likes