diff --git a/Serialiser_Engine/Convert/Json.cs b/Serialiser_Engine/Convert/Json.cs index 8212a2782..9af86f55d 100644 --- a/Serialiser_Engine/Convert/Json.cs +++ b/Serialiser_Engine/Convert/Json.cs @@ -29,6 +29,7 @@ using System; using System.Collections; using BH.oM.Base; +using BH.Engine.Base; namespace BH.Engine.Serialiser { @@ -63,11 +64,13 @@ public static string ToJson(this object obj) [Output("obj", "Object recovered from the Json string")] public static object FromJson(string json) { - if (json == "") - { + if (string.IsNullOrWhiteSpace(json)) return null; - } - else if (json.StartsWith("{")) + + // Trim the json to remove any trailing or initial whitespace/newline (#3109). + json = json.Trim(); + + if (json.StartsWith("{")) { BsonDocument document; if (BsonDocument.TryParse(json, out document)) @@ -87,7 +90,6 @@ public static object FromJson(string json) return FromJsonArray(json); } - else { // Could we do something when a string is not a valid json?