title: Is there a way to validate if a String is JSON format in C#?
body: <p>I tried using <a href="https://stackoverflow.com/questions/14977848/how-to-make-sure-that-string-is-valid-json-using-json-net">code I found in this answer</a> :-</p>
  
  <pre><code>        strInput = strInput.Trim();
          if ((strInput.StartsWith("{") &amp;&amp; strInput.EndsWith("}")) || //For object
              (strInput.StartsWith("[") &amp;&amp; strInput.EndsWith("]"))) //For array
          {
              try
              {
                  var obj = JToken.Parse(strInput);
                  return true;
              }
              catch (JsonReaderException jex)
              {
                  //Exception in parsing json
                  Console.WriteLine(jex.Message);
                  return false;
              }
              catch (Exception ex) //some other exception
              {
                  Console.WriteLine(ex.ToString());
                  return false;
              }
          }
          else
          {
              return false;
          }
  </code></pre>
  
  <p>Problem with this code is, that it validates wrong JSON Files as right, because JToken.Parse automatically deletes Elements that are doubled in the sequence for example:</p>
  
  <pre><code>{
     "Body" : {
        "Data" : {}
     },
     "Head" : {
        "RequestArguments" : {
           "Scope" : ""
        },
        "Status" : {
           "Code" : 255,
           "Reason" : "CGI-Args: Invalid parameter '' for Scope.",
           "UserMessage" : ""
        },
        "Timestamp" : "2017-01-24T13:15:33+01:00"
     },
     "Head" : {
        "RequestArguments" : {
           "Scope" : ""
        },
        "Status" : {
           "Code" : 255,
           "Reason" : "CGI-Args: Invalid parameter '' for Scope.",
           "UserMessage" : ""
        },
        "Timestamp" : "2017-01-24T13:15:33+01:00"
     }
  }
  </code></pre>
  
  <p>Here there are 2 Head Token on the same Level which are not allowed, but JToken automatically parses away one of the 2 Head Tokens so the resulting Object is valid</p>