Convert JSON Strings to VARCHAR and TEXT Columns

Learn how JSON string values map to SQL VARCHAR, TEXT, CHAR, and other string column types. Covers length estimation, encoding, and best practices.

Basic Tables

Detailed Explanation

String Type Mapping

JSON strings are the most common value type, but SQL offers multiple string types with different constraints and performance characteristics.

Default Mapping

{
  "name": "Alice Johnson",
  "email": "alice@example.com",
  "bio": "Full-stack developer with 10 years of experience building web applications, APIs, and distributed systems.",
  "country_code": "US",
  "uuid": "550e8400-e29b-41d4-a716-446655440000"
}
CREATE TABLE profiles (
  name VARCHAR(255) NOT NULL,
  email VARCHAR(255) NOT NULL,
  bio TEXT NOT NULL,
  country_code CHAR(2) NOT NULL,
  uuid CHAR(36) NOT NULL
);

Choosing the Right String Type

SQL type When to use
CHAR(n) Fixed-length: country codes, UUIDs, hash digests
VARCHAR(n) Variable-length with a known max: names, emails, URLs
TEXT Unbounded: descriptions, comments, markdown content

Length Estimation

The converter analyzes sample values to estimate lengths:

  1. Short fixed patterns (2-36 chars) — Uses CHAR(n) when all samples have identical length.
  2. Moderate strings (up to ~255 chars) — Uses VARCHAR(255) as a safe default.
  3. Long strings (>255 chars or variable) — Uses TEXT.

You can override the default VARCHAR length in the tool options.

Smart Detection

The converter recognizes common patterns in column names and values:

  • emailVARCHAR(320) (RFC 5321 max)
  • url, href, linkVARCHAR(2048)
  • phoneVARCHAR(20)
  • country_codeCHAR(2)
  • uuid, guidCHAR(36) or UUID (PostgreSQL)

Encoding Considerations

Always use UTF-8 (utf8mb4 in MySQL) to support emoji and international characters. The converter adds a comment if it detects non-ASCII characters in sample values.

Indexing Impact

TEXT columns cannot be directly indexed in MySQL (you need a prefix index). If you plan to filter or sort by a string column, prefer VARCHAR with an explicit length.

Use Case

You are converting API response data that contains a mix of short codes, medium-length names, and long-form text fields, and you need each column to use the most appropriate SQL string type.

Try It — JSON to SQL Schema

Open full tool