JSON Parse Error - Unterminated String on Write Tool #8178

Closed
opened 2026-02-16 18:09:21 -05:00 by yindo · 6 comments
Owner

Originally created by @JacquesvanWyk on GitHub (Jan 31, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

Model: kimi-k2.5-free
Tool Affected: write (file write)
Error: JSON Parse error: Unterminated string
Summary
Large content strings (>4-5KB) with code blocks cause JSON parsing failures when using the write tool.
Reproduction

  1. Attempt to write file with content containing:
    • Markdown with SQL code blocks (triple backticks)
    • Unicode box-drawing characters (│ ├ └)
    • Length > 4000 characters
  2. JSON parser fails with "Error message: JSON Parse error: Unterminated string]"
    Suspected Causes
  • String length exceeding parser buffer
  • Improper escaping of nested quotes or backticks
  • Multibyte character handling issues
    Workaround
    Split content into smaller chunks (<3KB each) or use edit tool for incremental writes.
    Environment
  • Platform: darwin/macOS
  • Working with: Technical documentation, SQL schemas, code examples

Plugins

No response

OpenCode version

1.1.40

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

macOS Tahoe Version 26.2

Terminal

Ghostty

Originally created by @JacquesvanWyk on GitHub (Jan 31, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description **Model:** kimi-k2.5-free **Tool Affected:** `write` (file write) **Error:** `JSON Parse error: Unterminated string` Summary Large content strings (>4-5KB) with code blocks cause JSON parsing failures when using the write tool. Reproduction 1. Attempt to write file with content containing: - Markdown with SQL code blocks (triple backticks) - Unicode box-drawing characters (│ ├ └) - Length > 4000 characters 2. JSON parser fails with "Error message: JSON Parse error: Unterminated string]" Suspected Causes - String length exceeding parser buffer - Improper escaping of nested quotes or backticks - Multibyte character handling issues Workaround Split content into smaller chunks (<3KB each) or use edit tool for incremental writes. Environment - Platform: darwin/macOS - Working with: Technical documentation, SQL schemas, code examples ### Plugins _No response_ ### OpenCode version 1.1.40 ### Steps to reproduce _No response_ ### Screenshot and/or share link _No response_ ### Operating System macOS Tahoe Version 26.2 ### Terminal Ghostty
yindo added the bug label 2026-02-16 18:09:21 -05:00
yindo closed this issue 2026-02-16 18:09:21 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 31, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #5890: Incomplete JSON when writing out files - Reports similar JSON parsing errors with incomplete output when writing files
  • #10967: Error Writing Large Files (at least with Kimi K2.5) - Specifically mentions Kimi K2.5 model with large file writes causing JSON parsing failures
  • #10755: openai/gpt-5.2-codex 'Error message: JSON Parse error: Unterminated string' errors - Similar JSON parsing errors with unterminated strings during normal usage
  • #1278: JSON Parse error: Unterminated string with openrouter/kimi-k2 - Earlier report of the same unterminated string error with Kimi model

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 31, 2026): This issue might be a duplicate of existing issues. Please check: - #5890: Incomplete JSON when writing out files - Reports similar JSON parsing errors with incomplete output when writing files - #10967: Error Writing Large Files (at least with Kimi K2.5) - Specifically mentions Kimi K2.5 model with large file writes causing JSON parsing failures - #10755: openai/gpt-5.2-codex 'Error message: JSON Parse error: Unterminated string' errors - Similar JSON parsing errors with unterminated strings during normal usage - #1278: JSON Parse error: Unterminated string with openrouter/kimi-k2 - Earlier report of the same unterminated string error with Kimi model Feel free to ignore if none of these address your specific case.
Author
Owner

@rekram1-node commented on GitHub (Jan 31, 2026):

can u provide a prompt to reproduce?

@rekram1-node commented on GitHub (Jan 31, 2026): can u provide a prompt to reproduce?
Author
Owner

@JacquesvanWyk commented on GitHub (Jan 31, 2026):

can u provide a prompt to reproduce?

Looks like its when its trying large write

⚙ invalid [tool=write, error=Invalid input for tool write: JSON parsing failed: Text: {"content": "# TownHub - Multi-Town Community Platform\n## Technical Specification Document v1.0\n\n---\n\n## 1. EXECUTIVE SUMMARY\n\nProduct Name: TownHub\nPurpose: Hyperlocal platform connecting residents with local businesses, events, and community information across multiple towns.\nTarget Market: South African towns (initially), with global scalability potential.\nRevenue Model: Freemium SaaS (business subscriptions) + transaction fees + advertising\nTech Stack: Laravel API (Backend) + Nuxt.js (Web) + Flutter (Mobile)\n\n---\n\n## 2. USER PERSONAS & USER STORIES\n\n### 2.1 User Types\n\nType A: Resident (Free User)\n- Discovers local businesses, events, and community updates\n- Can browse, search, review, and engage\n- Can post classifieds (limited free listings)\n- Can RSVP to events\n- Can message businesses\n\nType B: Business Owner\n- Basic tier: Free limited listing\n- Premium tier: R299/month - enhanced profile, analytics, unlimited deals\n- Pro tier: R699/month - booking system, priority placement, customer messaging\n- Enterprise: R999/month - white-label, API access, dedicated support\n\nType C: Town Administrator\n- Manages town settings and content moderation\n- Can broadcast emergency notifications\n- Views town analytics\n- Approves/rejects business claims\n\nType D: Super Admin (Platform Owner)\n- Manages all towns\n- User management across platform\n- Revenue analytics\n- System configuration\n\n### 2.2 Detailed User Stories\n\nAs a Resident:\n1. I want to join my town so I can see local content\n2. I want to search for businesses by category and location\n3. I want to view business details including hours, photos, and reviews\n4. I want to leave reviews and ratings for businesses I've visited\n5. I want to see upcoming events in my town and RSVP\n6. I want to buy/sell items locally through classifieds\n7. I want to receive notifications for events I'm attending\n8. I want to save businesses to favorites\n9. I want to share business listings via WhatsApp/SMS\n10. I want to see which businesses are currently open\n\nAs a Business Owner:\n1. I want to claim my business listing\n2. I want to update my business profile with photos, hours, description\n3. I want to create and manage deals/offers\n4. I want to post events to promote to the community\n5. I want to respond to customer reviews\n6. I want to see analytics on profile views and engagement\n7. I want to receive messages from potential customers\n8. I want to manage my subscription and billing\n9. I want to export customer data (with permissions)\n10. I want to integrate booking/appointment scheduling\n\nAs a Town Admin:\n1. I want to moderate community posts and remove inappropriate content\n2. I want to send broadcast notifications to all residents\n3. I want to approve business registrations in my town\n4. I want to view engagement metrics for my town\n5. I want to feature specific businesses or events\n6. I want to configure town-specific settings (categories, rules)\n7. I want to manage town residents and ban problematic users\n8. I want to export town analytics reports\n\n---\n\n## 3. DETAILED FEATURE SPECIFICATIONS\n\n### 3.1 AUTHENTICATION & USER MANAGEMENT\n\n3.1.1 Authentication System\n- Email/password registration with verification\n- Social login: Google, Facebook, Apple\n- Phone number verification (OTP via SMS)\n- JWT token-based authentication (Sanctum)\n- Password reset via email\n- Session management with refresh tokens\n- Rate limiting on login attempts (5 attempts per 15 minutes)\n\n3.1.2 User Profiles\nFields:\n- id (UUID)\n- email (unique, required)\n- phone_number (unique, optional)\n- first_name (required)\n- last_name (required)\n- avatar_url (nullable)\n- bio (text, max 500 chars, nullable)\n- date_of_birth (nullable)\n- gender (enum: male, female, other, prefer_not_to_say, nullable)\n- town_ids (array, many-to-many)\n- current_town_id (FK, nullable)\n- user_type (enum: resident, business_owner, town_admin, super_admin)\n- is_verified (boolean, default: false)\n- email_verified_at (timestamp)\n- phone_verified_at (timestamp)\n- notification_preferences (JSON)\n- privacy_settings (JSON)\n- created_at, updated_at, deleted_at\n\n3.1.3 User Roles & Permissions\nRoles:\n- resident: Basic browsing and engagement\n- business_owner: Can manage owned businesses\n- town_admin: Can moderate content in assigned towns\n- super_admin: Full platform access\n\nPermissions implemented via Laravel Spatie or custom middleware:\n- view_businesses\n- create_business\n- edit_own_business\n- delete_own_business\n- post_classified\n- create_event\n- moderate_content\n- broadcast_notifications\n- view_analytics\n- manage_subscriptions\n\n### 3.2 TOWN MANAGEMENT\n\n3.2.1 Town Entity\nFields:\n- id (UUID)\n- name (required, unique per country)\n- slug (required, URL-friendly)\n- description (text)\n- country (required, default: ZA)\n- province (required for SA)\n- city/town classification\n- latitude, longitude (for geofencing)\n- radius_km (service area radius)\n- cover_image_url\n- logo_url\n- primary_color, secondary_color (for branding)\n- timezone (default: Africa/Johannesburg)\n- currency (default: ZAR)\n- is_active (boolean)\n- is_featured (boolean)\n- settings (JSON: moderation_rules, posting_limits, etc.)\n- created_by (FK to users)\n- created_at, updated_at\n\n3.2.2 User-Town Relationship\nTable: user_town_memberships\n- id\n- user_id (FK)\n- town_id (FK)\n- role (enum: member, moderator, admin)\n- joined_at (timestamp)\n- is_primary (boolean)\n- notification_enabled (boolean)\n\n3.2.3 Town Joining Logic\n- Users can join multiple towns\n- User selects primary town (default view)\n- Can switch towns via town selector\n- Can discover nearby towns via geolocation\n- Must be approved to join private towns (rare)\n\n### 3.3 BUSINESS DIRECTORY\n\n3.3.1 Business Entity\nFields:\n- id (UUID)\n- name (required, max 255)\n- slug (required, unique per town)\n- description (text, max 5000)\n- short_description (text, max 160, for SEO)\n- town_id (FK, required)\n- owner_user_id (FK, nullable until claimed)\n- category_id (FK, required)\n- subcategory_ids (array of FKs)\n- status (enum: pending, active, suspended, closed)\n- verification_status (enum: unclaimed, pending, verified, rejected)\n\nContact Information:\n- phone_number (required)\n- whatsapp_number (nullable)\n- email (required)\n- website_url (nullable)\n- social_links (JSON: facebook, instagram, twitter, linkedin, tiktok)\n\nLocation:\n- address_line_1 (required)\n- address_line_2 (nullable)\n- suburb (required)\n- postal_code (required)\n- latitude (required)\n- longitude (required)\n- google_place_id (nullable)\n\nBusiness Details:\n- business_type (enum: physical, online, both)\n- year_established (nullable)\n- employee_count (enum: solo, 2-5, 6-10, 11-25, 26-50, 50+)\n- tags (array of strings, max 10)\n\nMedia:\n- logo_url (nullable)\n- cover_image_url (nullable)\n- gallery_images (array of URLs, max 20)\n-.
Error message: JSON Parse error: Unterminated string]

@JacquesvanWyk commented on GitHub (Jan 31, 2026): > can u provide a prompt to reproduce? Looks like its when its trying large write ⚙ invalid [tool=write, error=Invalid input for tool write: JSON parsing failed: Text: {"content": "# TownHub - Multi-Town Community Platform\n## Technical Specification Document v1.0\n\n---\n\n## 1. EXECUTIVE SUMMARY\n\n**Product Name:** TownHub\n**Purpose:** Hyperlocal platform connecting residents with local businesses, events, and community information across multiple towns.\n**Target Market:** South African towns (initially), with global scalability potential.\n**Revenue Model:** Freemium SaaS (business subscriptions) + transaction fees + advertising\n**Tech Stack:** Laravel API (Backend) + Nuxt.js (Web) + Flutter (Mobile)\n\n---\n\n## 2. USER PERSONAS & USER STORIES\n\n### 2.1 User Types\n\n**Type A: Resident (Free User)**\n- Discovers local businesses, events, and community updates\n- Can browse, search, review, and engage\n- Can post classifieds (limited free listings)\n- Can RSVP to events\n- Can message businesses\n\n**Type B: Business Owner**\n- Basic tier: Free limited listing\n- Premium tier: R299/month - enhanced profile, analytics, unlimited deals\n- Pro tier: R699/month - booking system, priority placement, customer messaging\n- Enterprise: R999/month - white-label, API access, dedicated support\n\n**Type C: Town Administrator**\n- Manages town settings and content moderation\n- Can broadcast emergency notifications\n- Views town analytics\n- Approves/rejects business claims\n\n**Type D: Super Admin (Platform Owner)**\n- Manages all towns\n- User management across platform\n- Revenue analytics\n- System configuration\n\n### 2.2 Detailed User Stories\n\n**As a Resident:**\n1. I want to join my town so I can see local content\n2. I want to search for businesses by category and location\n3. I want to view business details including hours, photos, and reviews\n4. I want to leave reviews and ratings for businesses I've visited\n5. I want to see upcoming events in my town and RSVP\n6. I want to buy/sell items locally through classifieds\n7. I want to receive notifications for events I'm attending\n8. I want to save businesses to favorites\n9. I want to share business listings via WhatsApp/SMS\n10. I want to see which businesses are currently open\n\n**As a Business Owner:**\n1. I want to claim my business listing\n2. I want to update my business profile with photos, hours, description\n3. I want to create and manage deals/offers\n4. I want to post events to promote to the community\n5. I want to respond to customer reviews\n6. I want to see analytics on profile views and engagement\n7. I want to receive messages from potential customers\n8. I want to manage my subscription and billing\n9. I want to export customer data (with permissions)\n10. I want to integrate booking/appointment scheduling\n\n**As a Town Admin:**\n1. I want to moderate community posts and remove inappropriate content\n2. I want to send broadcast notifications to all residents\n3. I want to approve business registrations in my town\n4. I want to view engagement metrics for my town\n5. I want to feature specific businesses or events\n6. I want to configure town-specific settings (categories, rules)\n7. I want to manage town residents and ban problematic users\n8. I want to export town analytics reports\n\n---\n\n## 3. DETAILED FEATURE SPECIFICATIONS\n\n### 3.1 AUTHENTICATION & USER MANAGEMENT\n\n**3.1.1 Authentication System**\n- Email/password registration with verification\n- Social login: Google, Facebook, Apple\n- Phone number verification (OTP via SMS)\n- JWT token-based authentication (Sanctum)\n- Password reset via email\n- Session management with refresh tokens\n- Rate limiting on login attempts (5 attempts per 15 minutes)\n\n**3.1.2 User Profiles**\nFields:\n- id (UUID)\n- email (unique, required)\n- phone_number (unique, optional)\n- first_name (required)\n- last_name (required)\n- avatar_url (nullable)\n- bio (text, max 500 chars, nullable)\n- date_of_birth (nullable)\n- gender (enum: male, female, other, prefer_not_to_say, nullable)\n- town_ids (array, many-to-many)\n- current_town_id (FK, nullable)\n- user_type (enum: resident, business_owner, town_admin, super_admin)\n- is_verified (boolean, default: false)\n- email_verified_at (timestamp)\n- phone_verified_at (timestamp)\n- notification_preferences (JSON)\n- privacy_settings (JSON)\n- created_at, updated_at, deleted_at\n\n**3.1.3 User Roles & Permissions**\nRoles:\n- `resident`: Basic browsing and engagement\n- `business_owner`: Can manage owned businesses\n- `town_admin`: Can moderate content in assigned towns\n- `super_admin`: Full platform access\n\nPermissions implemented via Laravel Spatie or custom middleware:\n- `view_businesses`\n- `create_business`\n- `edit_own_business`\n- `delete_own_business`\n- `post_classified`\n- `create_event`\n- `moderate_content`\n- `broadcast_notifications`\n- `view_analytics`\n- `manage_subscriptions`\n\n### 3.2 TOWN MANAGEMENT\n\n**3.2.1 Town Entity**\nFields:\n- id (UUID)\n- name (required, unique per country)\n- slug (required, URL-friendly)\n- description (text)\n- country (required, default: ZA)\n- province (required for SA)\n- city/town classification\n- latitude, longitude (for geofencing)\n- radius_km (service area radius)\n- cover_image_url\n- logo_url\n- primary_color, secondary_color (for branding)\n- timezone (default: Africa/Johannesburg)\n- currency (default: ZAR)\n- is_active (boolean)\n- is_featured (boolean)\n- settings (JSON: moderation_rules, posting_limits, etc.)\n- created_by (FK to users)\n- created_at, updated_at\n\n**3.2.2 User-Town Relationship**\nTable: `user_town_memberships`\n- id\n- user_id (FK)\n- town_id (FK)\n- role (enum: member, moderator, admin)\n- joined_at (timestamp)\n- is_primary (boolean)\n- notification_enabled (boolean)\n\n**3.2.3 Town Joining Logic**\n- Users can join multiple towns\n- User selects primary town (default view)\n- Can switch towns via town selector\n- Can discover nearby towns via geolocation\n- Must be approved to join private towns (rare)\n\n### 3.3 BUSINESS DIRECTORY\n\n**3.3.1 Business Entity**\nFields:\n- id (UUID)\n- name (required, max 255)\n- slug (required, unique per town)\n- description (text, max 5000)\n- short_description (text, max 160, for SEO)\n- town_id (FK, required)\n- owner_user_id (FK, nullable until claimed)\n- category_id (FK, required)\n- subcategory_ids (array of FKs)\n- status (enum: pending, active, suspended, closed)\n- verification_status (enum: unclaimed, pending, verified, rejected)\n\n**Contact Information:**\n- phone_number (required)\n- whatsapp_number (nullable)\n- email (required)\n- website_url (nullable)\n- social_links (JSON: facebook, instagram, twitter, linkedin, tiktok)\n\n**Location:**\n- address_line_1 (required)\n- address_line_2 (nullable)\n- suburb (required)\n- postal_code (required)\n- latitude (required)\n- longitude (required)\n- google_place_id (nullable)\n\n**Business Details:**\n- business_type (enum: physical, online, both)\n- year_established (nullable)\n- employee_count (enum: solo, 2-5, 6-10, 11-25, 26-50, 50+)\n- tags (array of strings, max 10)\n\n**Media:**\n- logo_url (nullable)\n- cover_image_url (nullable)\n- gallery_images (array of URLs, max 20)\n-. Error message: JSON Parse error: Unterminated string]
Author
Owner

@shmish111 commented on GitHub (Feb 1, 2026):

I had this issue and it's a real PITA because everything stops and it seems opencode doesn't realise. If I tell it the error and tell it to use a sub agent then it will eventually work. I assume it sees the error output from the sub agent but not from itself.

@shmish111 commented on GitHub (Feb 1, 2026): I had this issue and it's a real PITA because everything stops and it seems opencode doesn't realise. If I tell it the error and tell it to use a sub agent then it will eventually work. I assume it sees the error output from the sub agent but not from itself.
Author
Owner

@rekram1-node commented on GitHub (Feb 2, 2026):

make sure you are on latest, if you installed via brew make sure you are using correct tap:
brew install anomalyco/tap/opencode

This was fixed in 1.1.41

@rekram1-node commented on GitHub (Feb 2, 2026): make sure you are on latest, if you installed via brew make sure you are using correct tap: `brew install anomalyco/tap/opencode` This was fixed in 1.1.41
Author
Owner

@qingmo commented on GitHub (Feb 6, 2026):

make sure you are on latest, if you installed via brew make sure you are using correct tap: brew install anomalyco/tap/opencode

This was fixed in 1.1.41

brew info opencode
==> opencode ✔: stable 1.1.50 (bottled)
the problem still appeared when write into file with a large content which are produced by ai model.

temp solution
⚙ invalid [tool=write, error=Invalid input for tool write: JSON parsing failed: Text: {"filePath": "xxxx.md".
Error message: JSON Parse error: Expected '}']
▣ Build · claude-sonnet · 2m 39s
Promot:Do not write all at once; write in batches to avoid writing issues.
it works

@qingmo commented on GitHub (Feb 6, 2026): > make sure you are on latest, if you installed via brew make sure you are using correct tap: `brew install anomalyco/tap/opencode` > > This was fixed in 1.1.41 brew info opencode ==> opencode ✔: stable 1.1.50 (bottled) the problem still appeared when write into file with a large content which are produced by ai model. **temp solution** ⚙ invalid [tool=write, error=Invalid input for tool write: JSON parsing failed: Text: {"filePath": "xxxx.md". Error message: JSON Parse error: Expected '}'] ▣ Build · claude-sonnet · 2m 39s Promot:Do not write all at once; write in batches to avoid writing issues. it works
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8178