---
title: Integrate Monaco Editor into Survey Creator
product: Survey Creator
description: Integrate Monaco Editor into the Survey Creator JSON Editor tab. Try syntax highlighting, code folding, find and replace, JSON formatting, and error feedback in this JavaScript demo.
framework: React
source: https://surveyjs.io/survey-creator/examples/monaco-editor-integration/reactjs
index: https://surveyjs.io/survey-creator/examples/overview.md
---

# Integrate Monaco Editor into Survey Creator (React)

[Monaco Editor](https://microsoft.github.io/monaco-editor/) is the code editor that powers Visual Studio Code. This demo shows how to integrate Monaco in the Survey Creator for use in the JSON Editor tab. Try editing the schema, searching for a question name, or folding a JSON object. To format the schema, right-click the editor and select **Format Document**. Hover over an underlined error to view its message.

> Monaco integration requires Survey Creator v3.2.6 or newer.

Install the `monaco-editor` npm package:

```sh
npm install monaco-editor
```

Expose Monaco as `window.monaco` before creating a Survey Creator instance:

```js
import * as monaco from "monaco-editor";
import { SurveyCreatorModel } from "survey-creator-core";

Object.assign(window, { monaco });

const creator = new SurveyCreatorModel();
```

Monaco's JSON language features use web workers. For worker configuration and further setup instructions, see [Integrate Monaco into the JSON Editor Tab](/survey-creator/documentation/integrate-monaco-or-ace-editor-into-survey-creator#integrate-monaco).

## Files

### `public/index.html`

```html
<link href="https://fonts.googleapis.com/css?family=Open%20Sans:400,600&display=swap" rel="stylesheet">
<div id="surveyCreatorContainer" style="position: absolute; height: 100%; width: 100%"></div>
```

### `src/monaco_setup.js`

```js
import * as monaco from "monaco-editor";

self.MonacoEnvironment = {
  getWorker(_, label) {
    if (label === "json") {
      return new Worker(new URL("monaco-editor/language/json/json.worker.js", import.meta.url), { type: "module" });
    }
    return new Worker(new URL("monaco-editor/editor/editor.worker.js", import.meta.url), { type: "module" });
  }
};

Object.assign(window, { monaco });
```

### `src/survey_json.js`

```js
export const surveyJSON = {
  "title": "NPS Survey Question",
  "logo": "https://surveyjs.io/Content/Images/examples/logo.png",
  "logoHeight": "60px",
  "pages": [
    {
      "name": "page1",
      "elements": [
        {
          "type": "rating",
          "name": "nps_score",
          "title": "On a scale of zero to ten, how likely are you to recommend our product to a friend or colleague?",
          "isRequired": true,
          "rateMin": 0,
          "rateMax": 10,
          "minRateDescription": "(Most unlikely)",
          "maxRateDescription": "(Most likely)"
        },
        {
          "type": "checkbox",
          "name": "promoter_features",
          "visibleIf": "{nps_score} >= 9",
          "title": "Which of the following features do you value the most?",
          "description": "Please select no more than three features.",
          "isRequired": true,
          "validators": [
            {
              "type": "answercount",
              "text": "Please select no more than three features.",
              "maxCount": 3
            }
          ],
          "showOtherItem": true,
          "choices": [
            "Performance",
            "Stability",
            "User interface",
            "Complete functionality",
            "Learning materials (documentation, demos, code examples)",
            "Quality support"
          ],
          "otherText": "Other features:",
          "colCount": 2
        },
        {
          "type": "comment",
          "name": "passive_experience",
          "visibleIf": "{nps_score} >= 7  and {nps_score} <= 8",
          "title": "What can we do to make your experience more satisfying?"
        },
        {
          "type": "comment",
          "name": "disappointing_experience",
          "visibleIf": "{nps_score} <= 6",
          "title": "Please let us know why you had such a disappointing experience with our product"
        }
      ]
    }
  ],
  "completedHtml": "<h3>Thank you for your feedback</h3>",
  "completedHtmlOnCondition": [
    {
      "expression": "{nps_score} >= 9",
      "html": "<h3>Thank you for your feedback</h3> <h4>We are glad that you love our product. Your ideas and suggestions will help us make it even better.</h4>"
    },
    {
      "expression": "{nps_score} >= 6  and {nps_score} <= 8",
      "html": "<h3>Thank you for your feedback</h3> <h4>We are glad that you shared your ideas with us. They will help us make our product better.</h4>"
    }
  ]
};
```

### `src/SurveyCreatorComponent.jsx`

```js
import React from "react";
import { SurveyCreator, SurveyCreatorComponent } from "survey-creator-react";
import "survey-core/survey.i18n";
import "survey-creator-core/survey-creator-core.i18n";
import { surveyJSON } from "./survey_json";
import "./monaco_setup";

import "survey-core/survey-core.css";
import "survey-creator-core/survey-creator-core.css";
import "./index.css";

import SurveyTheme from "survey-core/themes";
import { registerCreatorTheme } from "survey-creator-core";

registerCreatorTheme(SurveyTheme); // Add predefined Survey Creator UI themes

function SurveyCreatorRenderComponent() {
    const creator = new SurveyCreator();
    creator.JSON = surveyJSON;
    creator.switchTab("json");
    
    return (<SurveyCreatorComponent creator={creator} />);
}

export default SurveyCreatorRenderComponent;
```

### `src/index.css`

```css
/* You can add your custom CSS here. */
```

### `src/index.js`

```js
import React from "react";
import { createRoot } from "react-dom/client";
import SurveyCreatorRenderComponent from "./SurveyCreatorComponent";

const root = createRoot(document.getElementById("surveyCreatorContainer"));
root.render(<SurveyCreatorRenderComponent />);
```

### `package.json`

```json
{
  "dependencies": {
    "react": "latest",
    "react-dom": "latest",
    "monaco-editor": "0.57.0",
    
    "survey-core": "latest",
    "survey-react-ui": "latest",
    "survey-creator-core": "latest",
    "survey-creator-react": "latest"
  },
  "devDependencies": {
    "react-scripts": "latest"
  }
}
```

## Other Frameworks

- [Angular](https://surveyjs.io/survey-creator/examples/monaco-editor-integration/angular.md)
- [Vue 3](https://surveyjs.io/survey-creator/examples/monaco-editor-integration/vue3js.md)
- [jQuery](https://surveyjs.io/survey-creator/examples/monaco-editor-integration/jquery.md)
- [Vanilla JS](https://surveyjs.io/survey-creator/examples/monaco-editor-integration/vanillajs.md)
