In doing a few JSON projects using YAJL I have run into the same issue a couple times.
JSON, it seems, requires a leading zero before the decimal point in a numeric value.
When using the %char Built in Function (BIF) the zero preceding the decimal point is removed. So, the best option I have discovered is pulling an old trick out of the bag and using the %editw BIF.
Let's say we have a field defined a numeric with 5 digits and 3 decimal places:
D tax_perc 5 3 INZ
If we try to use the following:
We will end up with:
But, if we use:
yajl_addChar('percent':%editw(tax_perc:'0 . '));
Then we end up with the proper format required by JSON:
Where you place the "0" in the edit word will tell the system when to stop zero suppressing the output. In this case, it will stop right before the decimal.
I'm sure there are more ways to do this, but this is what has worked for me.
I have found this H Spec takes care of the issue without additional coding. Just the usual:
Thanks for the info!