text in · typed json out

CSV to JSON with type inference — postcodes stay strings

Every cell in a CSV is just text. This decides what each one really is — and keeps the things that should stay text, like a leading-zero postcode, as text.

Converter — Ready
Awaiting input
idle — paste CSV and the typed objects show up here
0 records 0 columns Auto delimiter
runs entirely in your browser
nothing is uploaded, ever
no sign-up, no account
free — no paid tier, ever
Do it in code

Writing the inference yourself

Type inference is the part people get wrong, so it is worth seeing it spelled out. The rule is simple: try the most specific type first, and fall back to a string. The important detail is the last one - anything that looks like a number but is not meant to be one has to stay text.

import csv
import json


def infer(value):
    """Guess the type of one CSV cell."""
    s = value.strip()

    if s == "":
        return None                      # an empty cell is null
    if s.lower() in ("true", "false"):
        return s.lower() == "true"       # a real boolean
    if s.lower() == "null":
        return None

    # Only a clean integer or decimal becomes a number.
    try:
        return int(s)
    except ValueError:
        pass
    try:
        return float(s)
    except ValueError:
        pass

    # Everything else - including "00123" - stays a string.
    return s


with open("data.csv", newline="", encoding="utf-8") as f:
    rows = [{k: infer(v) for k, v in row.items()} for row in csv.DictReader(f)]

print(json.dumps(rows, indent=2))

Empty becomes null, true/false become booleans, plain numbers become numbers, everything else stays text

Note that int("00123") succeeds and quietly returns 123. That is why the function tries int() but the fallback keeps the original string - a leading zero is a strong signal that the value is an identifier, not a quantity. If you would rather have every value as a string, skip infer altogether and pass the raw cell through.

The converter above has the same switch: leave type inference on for a clean JSON array, or turn it off to keep the source text exactly as it was.

Worked example

A worked example

Six cells, six different outcomes - including the one that trips people up.

data.csv

id,zip,price,active,notes
1,01234,42.50,true,"Ships, fast"
2,10099,17,true,""

data.json

[
  {
    "id": 1,
    "zip": "01234",
    "price": 42.5,
    "active": true,
    "notes": "Ships, fast"
  },
  {
    "id": 2,
    "zip": 10099,
    "price": 17,
    "active": true,
    "notes": null
  }
]

Look at zip: the first value keeps its leading zero as text, the second is a plain number. Both came out of the same column, and both are correct - the inference follows the value, not the column. If you want the whole column to be a string, turn type inference off.

Step by step

Convert the file in the browser

Same file, same rules, and you can watch the types change.

  1. Paste the CSV

    Or drop a .csv file onto the box. The delimiter is detected automatically - comma, tab, semicolon or pipe.

  2. Check the header row

    The first row is used as the keys. If your file has no header, switch to the "no header" mode in the settings and the columns get numbered.

  3. Decide about types

    Type inference is on by default. Turn it off in the settings if every value should stay a string.

  4. Download the JSON

    Get the array as pretty-printed JSON, ready to paste into a request body.

Why HopConvert

Getting the types right

A JSON array is only as useful as the types inside it. These are the decisions that matter.

Leading zeros survive

A value like 01234 is kept as a string, because a code that starts with zero is an identifier, not a quantity.

Out-of-range numbers stay text

An integer too large for a 64-bit number is left as a string instead of being rounded in the display.

Real booleans and nulls

true and false become JSON booleans, and an empty cell becomes null rather than an empty string.

Turn it off when you want

One switch in the settings keeps every value exactly as the CSV held it, which is what you want for opaque IDs.

The complete guide

The full CSV to JSON guide

Header handling, quoting, delimiters and the type rules - the whole conversion explained.

Read the CSV to JSON guide

Related tools: CSV to JSON converter · JSON to CSV converter · JSON to SQL · JSON to Excel

FAQ

Frequently asked questions

The rules that decide what each cell becomes.

What types does it detect?
Four: null for an empty cell, true and false as booleans, integers and decimals as numbers, and everything else as a string. The order matters - a value is tried as a boolean before it is tried as a number.
Why did my leading zeros disappear?
The value was a number, so the leading zero was dropped as part of the conversion. Numbers that begin with a zero are treated as identifiers and kept as text, but a code like 00123 inside a larger value can still look numeric. Turning type inference off in the settings keeps every value exactly as the CSV had it.
How are empty cells handled?
An empty cell becomes null, not an empty string. The distinction matters when the JSON is compared against a schema or posted to an API that treats null and "" differently.
How do I keep everything as a string?
Turn off type inference in the settings, or skip the inference step in your own code. Every value then comes out exactly as the CSV cell held it, including leading zeros, trailing spaces and capitalisation.
What about a column that mixes numbers and text?
Inference follows the value, not the column. A cell reading 10099 becomes a number while the cell reading 01234 stays a string in the same column - which is usually what you want, and occasionally a warning sign that the column should be text everywhere.

Convert your CSV with the right types

Free, instant, and private — your CSV never leaves this tab.

Convert to JSON Read the FAQ