Issue parsing object with decimal in key name

I’m trying to upload a single object of type Abstract to a new stream. My python code looks something like this:

url = "https://{}/api/streams/{}".format(os.environ["SERVER"], stream_id)
payload = {"objects": [csv_to_speckle_object(fp)]}
r = requests.put(url, data=json.dumps(payload), headers=headers)

My payload looks like this when json encoded:

{
“objects”: [
{
“type”: “Abstract”,
“SpaceTypes”: {
“Atrium - Between 20ft and 40ft in height”: {
“Name”: “Atrium - Between 20ft and 40ft in height”,
“Equipment [W/m2]”: “5.38”,
“Equipment Variation Profile”: “Assembly - People”,
“Lighting [W/m2]”: “6.46”,
“Lighting Variation Profile”: “Assembly - Light”,
“Occupant Sensible Gain (W/person)”: “73.3”,
“Occupant Latent Gain (W/person)”: “73.3”,
“Occupant Density (people/m\u00ef\u00bf\u00bd)”: “1.61”,
“Occupant Variation Profile”: “Assembly - People”,
“ASHRAE 62.1 Category”: “”,
“62.1 Ventilation Coefficient Rp (m3/person)”: “0.00000”,
“62.1 Ventilation Coefficient Ra (m3/m\u00ef\u00bf\u00bd)”: “0.00000”,
“Infiltration [ACH]”: “0.5”
}…

The upload is successful, but when I try to read the contents of the stream, the objects are formatted in a way that looks like there’s an issue parsing the json where the decimals are. It looks like this:

{
“Atrium - Between 20ft and 40ft in height”: {
“62”: {
“1 Ventilation Coefficient Rp (m3/person)”: “0.00000”,
“1 Ventilation Coefficient Ra (m3/m�)”: “0.00000”,
},
“Name”: “Atrium - Between 20ft and 40ft in height”,
“Equipment [W/m2]”: “5.38”,
“Equipment Variation Profile”: “Assembly - People”,
“Lighting [W/m2]”: “6.46”,
“Lighting Variation Profile”: “Assembly - Light”,
“Occupant Sensible Gain (W/person)”: “73.3”,
“Occupant Latent Gain (W/person)”: “73.3”,
“Occupant Density (people/m�)”: “1.61”,
“Occupant Variation Profile”: “Assembly - People”,
“ASHRAE 62”: {“1 Category”: “”},
“Infiltration [ACH]”: “0.5”,
}…

Not quite sure how to get over this issue. Any suggestions would be great.

Cheers

Hey Tom! Sorry for the belated reply. It’s because dots in key names are quite the boo-boo for mongodb, see the docs: MongoDB Limits and Thresholds — MongoDB Manual

These chars are not allowed:

/\. "$

We filter for this partially in the gh components and stuff, but you’ll need a way to sanitise those property keys. Off the top of my head:

    public static string SanitizeKeyname( string keyName)
    {
      return keyName.Replace( ".", "☞" ); // BECAUSE FML
    }

    public static string UnsanitizeKeyname( string keyname)
    {
      return keyname.Replace( "☞", "." );
    }

Choose your poison…

Thanks Dimitrie. I figured it was an issue with the ‘.’ in the key name but couldn’t pin point where exactly it was happening.

Cheers