Piotr Czajkowski 2 years ago
parent
commit
f2ef537f55
2 changed files with 7 additions and 1 deletions
  1. 6 1
      analyzeJSON/AnalyzeJSON.cs
  2. 1 0
      analyzeJSONTests/AnalyzeJSONUnitTests.cs

+ 6 - 1
analyzeJSON/AnalyzeJSON.cs

@@ -1,6 +1,7 @@
 using System;
 using System.IO;
 using System.Linq;
+using System.Text.RegularExpressions;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
 
@@ -29,7 +30,11 @@ namespace analyzeJSON
 
         public static string GetNameFromPath(string tokenPath)
         {
-            return string.IsNullOrWhiteSpace(tokenPath) ? string.Empty : tokenPath.Split(".").Last();
+            if (string.IsNullOrWhiteSpace(tokenPath))
+                return string.Empty;
+
+            var name = tokenPath.Split(".").LastOrDefault();
+            return Regex.Replace(name, @"\[\d+?\]$", "");
         }
 
         private void Traverse(IJEnumerable<JToken> tokens, Action<JToken> action)

+ 1 - 0
analyzeJSONTests/AnalyzeJSONUnitTests.cs

@@ -68,6 +68,7 @@ namespace analyzeJSONTests
                 new TestCase("abc.def", "def"),
                 new TestCase("abc.", string.Empty),
                 new TestCase("abc.def.", string.Empty),
+                new TestCase("abc.def.ghi[0]", "ghi"),
 
             };