On Mon, May 06, 2019 at 12:20:24PM -0700, C K Kashyap wrote: > Thanks Alex, > I am not so concerned by number being the day of the week since the > assumption is that there is an implicit understanding of all the "types" in > the consuming code - I mean, it will be understood that all the numbers > need to be either used in mathematical expression or divided by the scale > if it is consumed directly.
OK, but I'd prefer a general solution. > The sed solution has the risk of altering strings that are unintended - I > can change it a bit to make it a little more robust - also I have to do it > twice since the first substitution may add .0 to numbers that are already > floats. > > sed -r 's/(:\s+)([0-9.]+)\b/\1\2.0/g' | sed -r > 's/(:\s+)([0-9]+)\.([0-9]+)\.0/\1\2.\3/g' Uh, a horror indeed! :) The PicoLisp way is usally different. It scans the stream with 'from', 'till', 'echo', 'peek' and 'char' etc. I would go for exactly the types we know to have the ".0" missing. This I tested for two cases, "volume" and "unadjustedVolume": (load "@lib/json.l") (scl 6) (pipe (in '("curl" "-s" "https://api.iextrading.com/1.0/stock/aapl/chart/3m") (while (prin (echo "volume" "unadjustedVolume") ) (echo ",") (prin ".0,") ) ) (pretty (readJson)) ) (prinl) You can add mere arguments to the 'echo' call if you know of other cases (I did not bother to study the data in detail). The code echoes all text until it hits one of the target strings. In such case it echoes the number till the comma, then prints ".0" and a comma. ☺/ A!ex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe