Skip to main content
Glama
paladini

devutils-mcp-server

json_validate

Validate JSON strings to detect parsing errors and identify their approximate locations for debugging and data integrity.

Instructions

Validate a JSON string and report any parsing errors with their approximate location.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputYesThe JSON string to validate

Implementation Reference

  • The implementation of the json_validate tool, which validates JSON strings and returns either a success message or an error with position and context.
    server.tool(
      "json_validate",
      "Validate a JSON string and report any parsing errors with their approximate location.",
      { input: z.string().describe("The JSON string to validate") },
      async ({ input }) => {
        try {
          JSON.parse(input);
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify(
                  { valid: true, message: "Valid JSON" },
                  null,
                  2
                ),
              },
            ],
          };
        } catch (e) {
          const message = e instanceof Error ? e.message : String(e);
    
          // Try to extract position info from error
          const posMatch = message.match(/position\s+(\d+)/i);
          const position = posMatch ? parseInt(posMatch[1], 10) : undefined;
    
          let context: string | undefined;
          if (position !== undefined) {
            const start = Math.max(0, position - 20);
            const end = Math.min(input.length, position + 20);
            context = input.slice(start, end);
          }
    
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify(
                  {
                    valid: false,
                    error: message,
                    position,
                    context,
                  },
                  null,
                  2
                ),
              },
            ],
          };
        }
      }
    );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/paladini/devutils-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server