java - Regex for JSON validation -


i'm trying regex validate json below. need validate if structure of json correct , nodes available regex validation in java code.

{"vehicles":[     {         "id"        :   "10001",         "storeid"   :   "101",         "purchasedate"  :   "2014-08-12",         "merchantname": "friends",         "category"  :   "sale",         "type"      :   "sedan",         "amount"    :   "15000.33"     },     {         "id"        :   "10002",         "storeid"   :   "101",         "purchasedate"  :   "2014-08-12",         "merchantname": "friends",         "category"  :   "lease",         "type"      :   "sedan",         "amount"    :   "25000.33"     },     {         "id"        :   "10003",         "accountid" :   "101",         "storeid"   :   "2014-08-12",         "merchantname": "friends",         "category"  :   "sale",         "type"      :   "suv",         "amount"    :   "36000.33"     } ]} 

thanks in advance!

you use gson purpose... following code might you

import com.google.gson.gson;  public final class jsonvalidation {  private static final gson gson = new gson();   public static boolean isvalidjson(string json) {    try {       gson.fromjson(json, object.class);       return true;   } catch(com.google.gson.jsonsyntaxexception ex) {        return false;   }   }  } 

you here more info... https://github.com/google/gson/blob/master/userguide.md


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -