public static String escapeDoubleQuotesForJson ( String text ) { if ( text == null ) { return null ; } StringBuilder builder = new StringBuilder ( text . length ( ) ) ; for ( int i = 0 ; i < text . length ( ) ; i ++ ) { char c = text . charAt ( i ) ; switch ( c ) { case ' ' : case ' ' : builder . append ( "\\" ) ; default : builder . append ( c ) ; } } return builder . toString ( ) ; }
If a text contains double quotes escape them .