public static Boolean isSyntaxValid(String input){
  if (input != null) {
    Stack<Character> stack=new Stack<Character>();
    if (input.length() > 0) {
      for (int i=0; i < input.length(); i++) {
        char ch=input.charAt(i);
        if ('\\' == ch) {
          i++;
          continue;
        }
        if (isValueEnclosingChar(ch)) {
          if (EnclosingCharacters.DOUBLE_QUOTATION == ch) {
            Character popped=stack.pop();
            if (popped == EnclosingCharacters.DOUBLE_QUOTATION) {
            }
 else {
              if (popped != null) {
                stack.push(popped);
              }
              stack.push(ch);
            }
          }
 else           if (EnclosingCharacters.SINGLE_QUOTATION == ch) {
            Character popped=stack.pop();
            if (popped == EnclosingCharacters.SINGLE_QUOTATION) {
            }
 else {
              if (popped != null) {
                stack.push(popped);
              }
              stack.push(ch);
            }
          }
 else {
            if (isOpeningBracket(ch)) {
              stack.push(ch);
            }
 else {
              Character popped=stack.pop();
              if (matches(popped,ch)) {
              }
 else {
                return false;
              }
            }
          }
        }
      }
    }
    if (stack.isEmpty()) {
      return true;
    }
 else {
      return false;
    }
  }
 else {
    return false;
  }
}

public static Boolean isSyntaxValid ( String input ) { if ( input != null ) { Stack < Character > stack = new Stack < Character > ( ) ; if ( input . length ( ) > 0 ) { for ( int i = 0 ; i < input . length ( ) ; i ++ ) { char ch = input . charAt ( i ) ; if ( '\\' == ch ) { i ++ ; continue ; } if ( isValueEnclosingChar ( ch ) ) { if ( EnclosingCharacters . DOUBLE_QUOTATION == ch ) { Character popped = stack . pop ( ) ; if ( popped == EnclosingCharacters . DOUBLE_QUOTATION ) { } else { if ( popped != null ) { stack . push ( popped ) ; } stack . push ( ch ) ; } } else if ( EnclosingCharacters . SINGLE_QUOTATION == ch ) { Character popped = stack . pop ( ) ; if ( popped == EnclosingCharacters . SINGLE_QUOTATION ) { } else { if ( popped != null ) { stack . push ( popped ) ; } stack . push ( ch ) ; } } else { if ( isOpeningBracket ( ch ) ) { stack . push ( ch ) ; } else { Character popped = stack . pop ( ) ; if ( matches ( popped , ch ) ) { } else { return false ; } } } } } } if ( stack . isEmpty ( ) ) { return true ; } else { return false ; } } else { return false ; } }
this function will check for the validity of the input provided . for e . g ; ' " input " ' is valid but ' " input ' is not a valid input same is the case with input like a json string
