{"id":1509,"date":"2015-05-21T11:40:36","date_gmt":"2015-05-21T03:40:36","guid":{"rendered":"https:\/\/cowmanchiang.me\/wp\/?p=1509"},"modified":"2023-10-31T15:43:31","modified_gmt":"2023-10-31T07:43:31","slug":"java-check-json-body","status":"publish","type":"post","link":"https:\/\/cowmanchiang.me\/wp\/?p=1509","title":{"rendered":"[Java] Check Json body."},"content":{"rendered":"<p>Ref: <a href=\"http:\/\/stackoverflow.com\/questions\/10174898\/how-to-check-whether-a-given-string-is-valid-json-in-java\">stackoverflow\uff1aHow to check whether a given string is valid JSON in Java<\/a><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">public boolean isJSONValid(String test) {\n  try {\n      new JSONObject(test);\n  } catch (JSONException ex) {\n      \/\/ edited, to include @Arthur&#039;s comment\n      \/\/ e.g. in case JSONArray is valid as well...\n      try {\n          new JSONArray(test);\n      } catch (JSONException ex1) {\n          return false;\n      }\n  }\n  return true;\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Ref: stackoverflow\uff1aHow to check whether a given string is valid JSON in Java public boolean isJSONValid(String test) { try { new JSONObject(test); } catch (JSONException ex) { \/\/ edited, to include @Arthur&#039;s comment \/\/ e.g. in case JSONArray is valid &hellip; <a href=\"https:\/\/cowmanchiang.me\/wp\/?p=1509\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[],"class_list":["post-1509","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1509","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1509"}],"version-history":[{"count":1,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1509\/revisions"}],"predecessor-version":[{"id":1912,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1509\/revisions\/1912"}],"wp:attachment":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}