-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathjson.cfc
27 lines (18 loc) · 858 Bytes
/
json.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<cfcomponent>
<!--- encodeJSON --->
<cffunction name="encode" access="public" returntype="String">
<cfargument name="data" type="Any" required="yes">
<cfargument name="stringNumbers" type="boolean" required="no" default="false"><!--- TODO: implement this --->
<cfset var result = ''>
<cfset result = REReplace(SerializeJSON(arguments.data),'("[A-Z]*"[ ]?:)','\L\1','All')>
<cfset result = REReplace(result,'("[A-Z]*[0-9]"[ ]?:)','\L\1','All')>
<cfreturn reReplace(result,'([_a-zA-Z]*)(":)','\L\1\2','ALL')>
</cffunction>
<!--- decodeJSON --->
<cffunction name="decode" access="public" returntype="Any">
<cfargument name="data" type="String" required="yes">
<cfset var result = ''>
<cfset result = DeserializeJSON(arguments.data)>
<cfreturn result>
</cffunction>
</cfcomponent>