File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -309,11 +309,24 @@ const getValue = (element) => {
309309 value = [ value ] ;
310310 }
311311
312- if ( value && ( valueType == 'object' || valueType == 'json' ) ) {
312+ if ( value && ( valueType === 'object' || valueType = == 'json' ) ) {
313313 try {
314- value = JSON . parse ( value )
314+ value = JSON . parse ( value ) ;
315315 } catch ( error ) {
316- value = value
316+ // Fallback to regex extraction if JSON parsing fails
317+ const jsonRegex = / ( \{ [ \s \S ] * \} | \[ [ \s \S ] * \] ) / ;
318+ const match = value . match ( jsonRegex ) ;
319+
320+ if ( match ) {
321+ try {
322+ value = JSON . parse ( match [ 0 ] ) ;
323+ } catch ( e ) {
324+ // If parsing still fails, keep the original value or handle the error
325+ console . error ( 'Failed to parse JSON after regex extraction:' , e ) ;
326+ }
327+ } else {
328+ console . error ( 'No valid JSON structure found in the string.' ) ;
329+ }
317330 }
318331 }
319332
You can’t perform that action at this time.
0 commit comments