korbit-ai[bot] commented on code in PR #31998:
URL: https://github.com/apache/superset/pull/31998#discussion_r1930299059


##########
superset-frontend/plugins/plugin-chart-handlebars/src/components/Handlebars/HandlebarsViewer.tsx:
##########
@@ -99,5 +99,18 @@ Handlebars.registerHelper(
   },
 );
 
+// usage: {{parseJson jsonString}}
+Handlebars.registerHelper('parseJson', (jsonString: string) => {
+  try {
+    const parsed = JSON.parse(jsonString);
+    if (Array.isArray(parsed)) {
+      return parsed;
+    }
+    throw new Error('Parsed value is not an array.');
+  } catch (error) {
+    throw new Error(`Invalid JSON string: ${error.message}`);
+  }
+});

Review Comment:
   ### parseJson Helper Incorrectly Restricted to Arrays Only <sub>![category 
Functionality](https://img.shields.io/badge/Functionality-0284c7)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The parseJson helper only accepts arrays and throws an error for valid JSON 
objects, which contradicts the stated purpose of handling nested JSON data 
structures.
   
   ###### Why this matters
   Users will be unable to parse valid JSON objects containing nested data, 
limiting the helper's utility and preventing common use cases like parsing 
nested configuration objects.
   
   ###### Suggested change ∙ *Feature Preview*
   ```typescript
   Handlebars.registerHelper('parseJson', (jsonString: string) => {
     try {
       return JSON.parse(jsonString);
     } catch (error) {
       throw new Error(`Invalid JSON string: ${error.message}`);
     }
   });
   ```
   
   
   </details>
   
   <sub>💡 Does this comment miss the mark? [Tell us 
why](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/d5bc2a08-0883-4a46-be64-9a31c84a06f6?suggestedFixEnabled=true)
 and Korbit will adapt to your team’s feedback.
   💬 Chat with Korbit by mentioning @korbit-ai.
   </sub>
   
   <!--- korbi internal id:aeb5da44-1553-41ad-ad73-a1e321a6e532 -->
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to