JSON Serialize Online
See how your data serializes to JSON with different settings: compact or indented, camelCase or snake_case names, nulls kept or left out. Then copy the matching settings for C#, Java, Python or JavaScript.
object → JSON text
Valid JSON · object with 5 keys · 3 levels deep · 215 bytes
{
"orderId": 1048,
"customerName": "Zoë Brown",
"giftMessage": null,
"items": [
{
"sku": "MUG-01",
"unitPrice": 8.5,
"qty": 2
},
{
"sku": "TEE-M",
"unitPrice": 15,
"qty": 1
}
],
"isPaid": true
}Everything runs in your browser; nothing is uploaded.
What does it mean to serialize JSON?
Serializing turns objects in your program into JSON text, so they can be sent in an API response, saved to a file or put on a queue. Deserializing is the reverse, reading the text back into objects.
The same object can serialize to different text depending on the serializer’s settings: whether it is indented, how property names are written, whether null values appear, and whether characters like é are escaped. The data is identical, but the other side of an API often expects one exact style, such as camelCase names, which is why these settings matter.
Serializing is sometimes called encoding (PHP’s json_encode) or stringifying (JavaScript’s JSON.stringify).
How to use the JSON serializer
- Paste a sample of your data as JSON, for example the output your code produces today.
- Choose the settings the receiving side expects: a naming style, compact or indented output, and whether to leave out nulls.
- Check the JSON tab for the exact result, then open your language’s tab to copy the serializer settings that produce it.
If two keys collapse into one name, for example user_id and userId both becoming userId, the tool warns you.
Example: C# property names to a camelCase API
A C# order has PascalCase properties, which is what you get when you serialize it with no settings. The JavaScript front end expects camelCase names and no nulls.
Step 1: Set the options
Step 2: The serialized JSON
Every name is now camelCase and GiftMessage is gone. Zoë keeps her ë because of the relaxed encoder; without it, System.Text.Json writes Zoë.
How each language serializes by default
With no settings at all, the common serializers give slightly different JSON for the same data:
| Serializer | Spacing | Names | Nulls | é |
|---|---|---|---|---|
| C# System.Text.Json | compact | as declared | written | \u00E9 |
| C# Newtonsoft.Json | compact | as declared | written | é |
| Java Jackson | compact | as declared | written | é |
| Python json.dumps | ", " and ": " | dict keys | null | \u00e9 |
| JavaScript JSON.stringify | compact | as in the object | written | é |
Two of these catch people out. Python’s default output isn’t fully compact, because it puts a space after every comma and colon: pass separators=(",", ":") for the smallest output. System.Text.Json escapes every non-ASCII character, and also < > & ' +, which is safe for HTML but hard to read. Use JavaScriptEncoder.UnsafeRelaxedJsonEscaping for JSON that isn’t embedded in HTML.
Common serialization errors
| Error | Cause | Fix |
|---|---|---|
A possible object cycle was detected (C#) · Self referencing loop detected (Newtonsoft) | Objects point at each other, e.g. order → customer → orders | ReferenceHandler.IgnoreCycles, or serialize a simpler DTO |
Converting circular structure to JSON (JavaScript) · Circular reference detected (Python) | The same loop in JavaScript or Python | Remove the back-reference before serializing |
Object of type datetime is not JSON serializable | Python’s json only knows dicts, lists, strings, numbers, bools and None | json.dumps(data, default=str), or .isoformat() |
Do not know how to serialize a BigInt | JSON.stringify can’t write BigInt values | Convert to a string first |
| Enums come out as numbers | C# writes enum values, not names, by default | Add JsonStringEnumConverter |
Frequently asked questions
What is the difference between serialize and stringify?
They mean the same thing: turning data into JSON text. JavaScript calls it stringify (JSON.stringify), PHP calls it encode (json_encode), and C#, Java and Python libraries call it serialize. "Stringify JSON" can also mean escaping JSON into a string, which is a second, separate step.
How do I serialize to camelCase in C#?
With System.Text.Json, set PropertyNamingPolicy = JsonNamingPolicy.CamelCase in JsonSerializerOptions (ASP.NET Core already does this for web APIs). With Newtonsoft, use a DefaultContractResolver with CamelCaseNamingStrategy.
Should I leave null values out of JSON?
It makes responses smaller, but only if the receiving code treats a missing key the same as null. In JavaScript a missing key reads as undefined, not null, so check the other side before you turn it on.
Does serializing change my numbers or key order?
Key order follows your class or object, unless you sort it. Numbers keep their value, but formatting can change: JavaScript and PHP write 10.0 as 10, while Newtonsoft.Json writes a whole double such as 15 as 15.0. JSON readers treat both forms the same.
Sources
- Microsoft Learn: Customize property names and values: naming policies and ignoring nulls
- Microsoft Learn: Character encoding with System.Text.Json: why é is escaped by default
- Newtonsoft.Json: Serialization settings: Formatting, NullValueHandling, naming strategies
- Jackson: Serialization features: INDENT_OUTPUT and ordering
- Python docs: json: indent, separators, sort_keys and ensure_ascii
- MDN: JSON.stringify(): replacer and space arguments
Related Tools
Build and preview Valorant crosshair settings.
Search common Vim commands.
Turn JSON rows into bar, line, or pie charts.
Convert WebP files and Base64 data in both directions.
Convert GIF files and Base64 data in both directions.
Save any GIF frame, or all frames, as JPG.