Skip to main content

Hello,

In some cases, JSONFormatter writes a decimal point number with the full precision of floating point numbers.

Example:

Source

{ "number" : 1.954, "string" : "1.954" }

Formatted by JSONFormetter (FME 2021.2.2)

{

  "number" : 1.9540000000000002,

  "string" : "1.954"

}

 

I think this document is desired in many cases.

{

  "number" : 1.954,

  "string" : "1.954"

}

 

Is there any way to prevent adding the excess decimal places?

I found Python json module can be used to format JSON document, but hope that the JSONFormatter would be improved not to add excess decimal places to numeric values.

PythonCaller Script Example

import json
def jsonPrettyPrint(feature):
    d = json.loads(feature.getAttribute('_json_document'))
    feature.setAttribute('_json_document', json.dumps(d, indent=3))
 

 


I found Python json module can be used to format JSON document, but hope that the JSONFormatter would be improved not to add excess decimal places to numeric values.

PythonCaller Script Example

import json
def jsonPrettyPrint(feature):
    d = json.loads(feature.getAttribute('_json_document'))
    feature.setAttribute('_json_document', json.dumps(d, indent=3))
 

 

Nice!


Reply