--- title: Validate JSON type: plugins category: Validation cat: validation order: 100 meta_title: Validate JSON meta_description: Checks that the introduced text is a valid JSON tier: enterprise ---!!! note For information about modifying this plugin or creating your own custom plugins, see [Customize and Build Your Own Plugins](custom). For general plugin information, see [Plugins for projects](/guide/plugins) and [Plugin FAQ](faq). ## About This plugin parses the contexts of a `TextArea` field to check for valid JSON. If the JSON is invalid, it shows an error and prevents the annotation from being saved. This is an example of a "hard" block, meaning that the user must resolve the issue before they can proceed.  ## Plugin ```javascript LSI.on("beforeSaveAnnotation", (store, annotation) => { const textAreaResult = annotation.results.find(r => r.type === 'textarea' && r.from_name.name === 'answer'); if (textAreaResult) { try { JSON.parse(textAreaResult.value.text[0]); } catch (e) { Htx.showModal("Invalid JSON format. Please correct the JSON and try again.", "error"); return false; } } return true; }); ``` **Related LSI instance methods:** * [on(eventName, handler)](custom#LSI-on-eventName-handler) **Related frontend events:** * [beforeSaveAnnotation](/guide/frontend_reference#beforeSaveAnnotation) ## Labeling config ```xml
``` **Related tags:** * [View](/tags/view.html) * [RectangleLabels](/tags/rectanglelabels.html) * [TextArea](/tags/textarea.html) * [Labels](/tags/labels.html) ## Sample data ```json [ { "image": "https://labelstud.io/demo/Datasets/Image/Object Detection/Image_66.jpg" } ] ```