I have a JSON-like input format:
{
"a": 2,
"b": 0.0,
"c": "hi"
}
There are Float values (always with decimal point) and Integer values (no decimal point). I need to parse it with Javascript, work with it and then write it back into file (floats with decimal point).
It is straight-forward to parse it into classic object, but I need to distinguish between Floats and Integers when encoding it back. I currently use this ugly JS structure:
{
type: "Object",
value: {
a: {type: "Integer", value: 2},
b: {type: "Float" , value: 0},
c: {type: "String" , value: "hi"}
}
}
I want to simplify my structure. Is there any way to distinguish Floats and Integers inside JS Numbers? Like "free bit" or something? Or maybe some smart trick?
E.g. if all my input numbers are always positive, I can store Integers as positive numbers, Floats as negative numbers. But they are not :( any other idea?