thegrumpys / odop

Open Design Optimization Platform (ODOP) - Coil spring design app; mechanical springs; compression spring, extension spring, torsion spring
https://www.springdesignsoftware.org
MIT License
4 stars 5 forks source link

Adopt JSON5 #861

Closed grumpyinca closed 11 months ago

grumpyinca commented 11 months ago

Investigate adopting JSON5 for various places where JSON is used within the ODOP system. Start with initialState files, the File : Save, File : Save As and File : Export features and their corresponding File : Open and File : Import features. JSON5 may also be appropriate for material files, standard size files and catalog files.

A big part of the motivation here is that JSON format lacks support for positive infinity, negative infinity, and NaN. Those values get mapped to null. Separately, JSON5 support for comments seems attractive.

1fifoto commented 11 months ago

After making the conversion from JSON to JSON5 we have encountered a problem. The problem is that the server uses JSON (not JSON5) inside of express server and its body parser to parse the data/message received from the client. As a result, the body parser fails to parse the data/message and generates an error.

A work around would be to use a JSON5 enabled express and its body parser. We found one, express-json5, but it was old and rarely used. As a result we feel that an alternative work around is needed.

This alternative would be to NOT USE JSON5, but to create a post-processor in the client on FileSave, FileSaveAs, or FileExport to encode only what we need. Specifically to encode and transmit NaN, positive Infinity, and negative Infinity as strings to the server. Then the server would receive this encoded form and save it into the database as-is. On the opposite end when loading via FileOpen, or FileImport the server would read the encoded data/message and transmit it to the client. The client would then decode the encoded NaN, positive Infinity, and negative Infinity strings into Number.NaN, Number.POSITIVE_INFINITY, or Number.NEGATIVE_INFINITY.

grumpyinca commented 11 months ago

While there is a significant amount of experimental code in this branch, nothing is or will be merged to master.

Closing the issue with no changes.