RE: JSON Encoding bug (again...)
Dave, The code testval = '.0006' makes me think a string instead of a number. Javacast might force a type on the string eh? Brooke - are you looking for a number or a string? -Mark -Original Message- From: Dave Watts [mailto:dwa...@figleaf.com] Sent: Monday, August 05, 2013 7:52 PM To: cf-talk Subject: Re: JSON Encoding bug (again...) I have had to do so many hacks to get serializeJSON() to play nice. I add a ~ to all yes/no strings so I don't get back true/false values, I have a series of regular expressions that quote values in the resulting JSON that don't get quoted and break on the client side. And now I have this issue: cfset x = {testval='.0006'} cfdump var=#serializeJSON(x)# Which outputs: {TESTVAL:6.0E-4} WTF? I am using CF 9,0,1,274733 Update Level /C:/ColdFusion9/lib/updates/hf901-4.jar Anybody know of a workaround for this? The source data is in a query which gets serialized after being converted to an array of structs. It would be too slow to check each field for values like this and modify them to return to the client. I need another Idea. Anyone? This isn't really a problem with JSON serialization, but with CF being typeless, and CF's tendency to autoconvert numbers into scientific notation. You can work around this by using precisionEvaluate(), the BigDecimal version of the Evaluate function: cfset x = {testval=precisionEvaluate(.0006)} cfdump var=#serializeJSON(x)# Note that this will add a leading zero. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ http://training.figleaf.com/ Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on GSA Schedule, and provides the highest caliber vendor-authorized instruction at our training centers, online, or onsite. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:356393 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: JSON Encoding bug (again...)
The code testval = '.0006' makes me think a string instead of a number. Javacast might force a type on the string eh? That might work, but the problem is that CF will continually reevaluate values every time they're used - as you'd expect in a typeless language. All you can do is force CF to treat a variable as a specific type for the current operation. Here we have two operations: in the first, we can tell CF to treat the struct value as a string, but in the second that's kind of hard to do. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ http://training.figleaf.com/ Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on GSA Schedule, and provides the highest caliber vendor-authorized instruction at our training centers, online, or onsite. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:356399 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
RE: JSON Encoding bug (again...)
Yeah... got it. -Original Message- From: Dave Watts [mailto:dwa...@figleaf.com] Sent: Tuesday, August 06, 2013 10:28 AM To: cf-talk Subject: Re: JSON Encoding bug (again...) The code testval = '.0006' makes me think a string instead of a number. Javacast might force a type on the string eh? That might work, but the problem is that CF will continually reevaluate values every time they're used - as you'd expect in a typeless language. All you can do is force CF to treat a variable as a specific type for the current operation. Here we have two operations: in the first, we can tell CF to treat the struct value as a string, but in the second that's kind of hard to do. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ http://training.figleaf.com/ Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on GSA Schedule, and provides the highest caliber vendor-authorized instruction at our training centers, online, or onsite. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:356401 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
JSON Encoding bug (again...)
I have had to do so many hacks to get serializeJSON() to play nice. I add a ~ to all yes/no strings so I don't get back true/false values, I have a series of regular expressions that quote values in the resulting JSON that don't get quoted and break on the client side. And now I have this issue: cfset x = {testval='.0006'} cfdump var=#serializeJSON(x)# Which outputs: {TESTVAL:6.0E-4} WTF? I am using CF 9,0,1,274733 Update Level /C:/ColdFusion9/lib/updates/hf901-4.jar Anybody know of a workaround for this? The source data is in a query which gets serialized after being converted to an array of structs. It would be too slow to check each field for values like this and modify them to return to the client. I need another Idea. Anyone? Brook ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:356382 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: JSON Encoding bug (again...)
Not that it helps, but the same happens in CF10 as well. On Mon, Aug 5, 2013 at 6:46 PM, Brook Davies cft...@logiforms.com wrote: I have had to do so many hacks to get serializeJSON() to play nice. I add a ~ to all yes/no strings so I don't get back true/false values, I have a series of regular expressions that quote values in the resulting JSON that don't get quoted and break on the client side. And now I have this issue: cfset x = {testval='.0006'} cfdump var=#serializeJSON(x)# Which outputs: {TESTVAL:6.0E-4} WTF? I am using CF 9,0,1,274733 Update Level /C:/ColdFusion9/lib/updates/hf901-4.jar Anybody know of a workaround for this? The source data is in a query which gets serialized after being converted to an array of structs. It would be too slow to check each field for values like this and modify them to return to the client. I need another Idea. Anyone? Brook ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:356383 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: JSON Encoding bug (again...)
I have had to do so many hacks to get serializeJSON() to play nice. I add a ~ to all yes/no strings so I don't get back true/false values, I have a series of regular expressions that quote values in the resulting JSON that don't get quoted and break on the client side. And now I have this issue: cfset x = {testval='.0006'} cfdump var=#serializeJSON(x)# Which outputs: {TESTVAL:6.0E-4} WTF? I am using CF 9,0,1,274733 Update Level /C:/ColdFusion9/lib/updates/hf901-4.jar Anybody know of a workaround for this? The source data is in a query which gets serialized after being converted to an array of structs. It would be too slow to check each field for values like this and modify them to return to the client. I need another Idea. Anyone? This isn't really a problem with JSON serialization, but with CF being typeless, and CF's tendency to autoconvert numbers into scientific notation. You can work around this by using precisionEvaluate(), the BigDecimal version of the Evaluate function: cfset x = {testval=precisionEvaluate(.0006)} cfdump var=#serializeJSON(x)# Note that this will add a leading zero. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ http://training.figleaf.com/ Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on GSA Schedule, and provides the highest caliber vendor-authorized instruction at our training centers, online, or onsite. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:356384 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
JSON Encoding Bug
I just want to say I think that it is seriously lame that Adobe has not fixed the encoding issues with serializeJSON() converting 'yes' / 'no' to true/false. Yes, you can append as string and then convert it back afterwards and all that, but that's just adding extra processing overhead and hoakiness(?), and this bug has been around for so long - its now officially annoying. Sorry, I know, I'm just ranting. Brook ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:350229 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm