[FS] JSON Writer
George_Anderson
Member Posts: 71 ✭✭
Has anyone written a function to convert a map to a JSON string? (Basically the inverse of parseJsonWithUnits).
Just looking for something rudimentary. It may be hard to do this if the map contains non-basic types. (e.g. after serializing a "plane", it wouldn't be straightforward to know that you needed to interpret the map as a plane when deserializing).
Tagged:
0
Comments
-
See the toString function implementations in string.fs -- that doesn't exactly produce JSON, but it's close in a number of cases.Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc0
-
I made this. It isn't a complete implementation (funkiness with arrays) but it does quite well. Hope that helps! Also, if you come up with improvements, I would happily integrate them. The feature is just so I can easily test it - to use in FS, you should just use `mapToJSON` feature.0
-
@ilya_baran Excellent, this is generally working nicely.I have what appears to be a bug with the JSON unit parser, but I may be mis-using something:println(parseJsonWithUnits("[\"-1.0 meter\"]"));Prints "[1.0 meter]"(It makes negative values with units positive). It doesn't happen with unitless negative values.
0 -
Good catch -- thanks. I can see where it is -- logging it.Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc0
-
For any future reader here, the bug has been fixed.
0 -
I eventually made this mini-library:It's very much inspired by the OnShape stdlib string functions, and it also includes a template for how you can restore types after deserializing.0


