{"id":581,"date":"2026-07-07T18:24:28","date_gmt":"2026-07-07T18:24:28","guid":{"rendered":"https:\/\/onlinejsonformatter.com\/blog\/?p=581"},"modified":"2026-07-07T18:24:29","modified_gmt":"2026-07-07T18:24:29","slug":"python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples","status":"publish","type":"post","link":"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/","title":{"rendered":"Python json.dump() vs json.dumps() \u2013 Complete Tutorial with Real-World Examples"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">You&#8217;ve got a Python dictionary. You need to work with JSON. You open the docs, and suddenly you&#8217;re staring at two functions that look almost identical: <strong>json.dump()<\/strong> and <strong>json.dumps()<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Which one should you use? Why do both exist? And what happens if you pick the wrong one?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If that sounds familiar, you&#8217;re not alone. This is one of those Python concepts that trips up developers at every level\u2014not because it&#8217;s complicated, but because the difference isn&#8217;t immediately obvious.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to inspect or format your JSON output while learning, you can also use our free<a href=\"https:\/\/onlinejsonformatter.com\/json-formatter\"> <strong>JSON Formatter tool<\/strong><\/a> to make your JSON easier to read and validate.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s clear it up once and for all.<\/p>\n\n\n\n<h1 id=\"h-what-s-the-quick-answer\" class=\"wp-block-heading\">What&#8217;s the Quick Answer?<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Before diving deep, here&#8217;s the short version:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>json.dumps()<\/strong> \u2192 Converts a Python object into a <strong>JSON string<\/strong><\/li>\n\n\n\n<li><strong>json.dump()<\/strong> \u2192 Writes a Python object as <strong>JSON directly to a file<\/strong><\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Easy way to remember:<\/strong> The extra <strong>&#8220;s&#8221;<\/strong> in <strong>dumps<\/strong> stands for <strong>string<\/strong>.<\/p>\n<\/blockquote>\n\n\n\n<h1 id=\"h-what-is-json-serialization-in-python\" class=\"wp-block-heading\">What Is JSON Serialization in Python?<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">JSON serialization is the process of converting a Python object (such as a dictionary, list, or number) into JSON format.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Python provides a built-in <strong>json<\/strong> module for this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import json<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">No installation required\u2014it&#8217;s included with Python.<\/p>\n\n\n\n<h1 id=\"h-understanding-json-dumps-convert-python-object-to-json-string\" class=\"wp-block-heading\">Understanding json.dumps() \u2013 Convert Python Object to JSON String<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><code>json.dumps()<\/code> converts a Python object into a JSON-formatted string.<\/p>\n\n\n\n<h2 id=\"h-syntax\" class=\"wp-block-heading\">Syntax<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>json.dumps(<br>    obj,<br>    *,<br>    skipkeys=False,<br>    ensure_ascii=True,<br>    indent=None,<br>    separators=None,<br>    default=None,<br>    sort_keys=False<br>)<\/code><\/pre>\n\n\n\n<h2 id=\"h-simple-example\" class=\"wp-block-heading\">Simple Example<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import json<br><br>user = {<br>    \"name\": \"Alex\",<br>    \"age\": 28,<br>    \"is_active\": True,<br>    \"tags\": &#91;\"python\", \"backend\"]<br>}<br><br>json_string = json.dumps(user)<br><br>print(json_string)<br>print(type(json_string))<\/code><\/pre>\n\n\n\n<h3 id=\"h-output\" class=\"wp-block-heading\">Output<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>{\"name\": \"Alex\", \"age\": 28, \"is_active\": true, \"tags\": &#91;\"python\", \"backend\"]}<br>&lt;class 'str'&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Notice how Python&#8217;s <code>True<\/code> automatically becomes JSON&#8217;s <code>true<\/code>.<\/p>\n\n\n\n<h2 id=\"h-pretty-printing-json\" class=\"wp-block-heading\">Pretty Printing JSON<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>json_string = json.dumps(user, indent=4)<br><br>print(json_string)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{<br>    \"name\": \"Alex\",<br>    \"age\": 28,<br>    \"is_active\": true,<br>    \"tags\": &#91;<br>        \"python\",<br>        \"backend\"<br>    ]<br>}<\/code><\/pre>\n\n\n\n<h2 id=\"h-sort-keys-alphabetically\" class=\"wp-block-heading\">Sort Keys Alphabetically<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>json.dumps(user, sort_keys=True, indent=4)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Useful when generating consistent output.<\/p>\n\n\n\n<h1 id=\"h-understanding-json-dump-write-json-directly-to-a-file\" class=\"wp-block-heading\">Understanding json.dump() \u2013 Write JSON Directly to a File<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Unlike <code>json.dumps()<\/code>, <code>json.dump()<\/code> writes JSON directly into a file.<\/p>\n\n\n\n<h2 id=\"h-syntax-0\" class=\"wp-block-heading\">Syntax<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>json.dump(<br>    obj,<br>    fp,<br>    *,<br>    skipkeys=False,<br>    ensure_ascii=True,<br>    indent=None,<br>    separators=None,<br>    default=None,<br>    sort_keys=False<br>)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, <strong>fp<\/strong> means <strong>file pointer<\/strong>.<\/p>\n\n\n\n<h2 id=\"h-simple-example-0\" class=\"wp-block-heading\">Simple Example<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import json<br><br>user = {<br>    \"name\": \"Alex\",<br>    \"age\": 28,<br>    \"is_active\": True,<br>    \"tags\": &#91;\"python\", \"backend\"]<br>}<br><br>with open(\"user.json\", \"w\") as f:<br>    json.dump(user, f, indent=4)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This creates a file named <strong>user.json<\/strong>.<\/p>\n\n\n\n<h2 id=\"h-reading-json-back\" class=\"wp-block-heading\">Reading JSON Back<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>with open(\"user.json\", \"r\") as f:<br>    loaded_user = json.load(f)<br><br>print(loaded_user&#91;\"name\"])<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Alex<\/code><\/pre>\n\n\n\n<h1 id=\"h-json-dump-vs-json-dumps-side-by-side-comparison\" class=\"wp-block-heading\">json.dump() vs json.dumps() \u2013 Side-by-Side Comparison<\/h1>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Feature<\/th><th>json.dumps()<\/th><th>json.dump()<\/th><\/tr><\/thead><tbody><tr><td>Returns<\/td><td>JSON string<\/td><td>None<\/td><\/tr><tr><td>Writes to file<\/td><td>\u274c No<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>Requires file object<\/td><td>\u274c No<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>Best for<\/td><td>APIs, network, memory<\/td><td>Saving JSON files<\/td><\/tr><tr><td>Memory usage<\/td><td>Stores JSON in memory<\/td><td>Writes directly to disk<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Visit Now Tool :- <a href=\"https:\/\/onlinejsonformatter.com\/json-beautifier\">JSON Beautifier tool<\/a><\/strong><\/p>\n\n\n\n<h1 id=\"h-real-world-examples\" class=\"wp-block-heading\">Real-World Examples<\/h1>\n\n\n\n<h2 id=\"h-example-1-api-response\" class=\"wp-block-heading\">Example 1 \u2013 API Response<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When building an API, you need a JSON string.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import json<br><br>def get_user_response(user_id):<br>    user = {<br>        \"id\": user_id,<br>        \"name\": \"Sarah\",<br>        \"role\": \"admin\"<br>    }<br><br>    return json.dumps(user)<br><br>response = get_user_response(42)<br><br>print(response)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\"id\": 42, \"name\": \"Sarah\", \"role\": \"admin\"}<\/code><\/pre>\n\n\n\n<h2 id=\"h-example-2-saving-configuration\" class=\"wp-block-heading\">Example 2 \u2013 Saving Configuration<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import json<br><br>config = {<br>    \"theme\": \"dark\",<br>    \"language\": \"en\",<br>    \"notifications\": True,<br>    \"max_retries\": 3<br>}<br><br>with open(\"config.json\", \"w\") as f:<br>    json.dump(config, f, indent=2)<br><br>print(\"Config saved.\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Perfect for application settings.<\/p>\n\n\n\n<h2 id=\"h-example-3-logging-events\" class=\"wp-block-heading\">Example 3 \u2013 Logging Events<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import json<br>from datetime import datetime<br><br>def log_event(event_type, details):<br><br>    log_entry = {<br>        \"timestamp\": datetime.utcnow().isoformat(),<br>        \"event\": event_type,<br>        \"details\": details<br>    }<br><br>    with open(\"events.log\", \"a\") as f:<br>        f.write(json.dumps(log_entry) + \"\\n\")<br><br>log_event(\"login\", {\"user\": \"bob\"})<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This creates <strong>NDJSON (Newline Delimited JSON)<\/strong>.<\/p>\n\n\n\n<h2 id=\"h-example-4-sending-data-over-a-socket\" class=\"wp-block-heading\">Example 4 \u2013 Sending Data Over a Socket<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import json<br><br>payload = {<br>    \"action\": \"update_status\",<br>    \"user_id\": 101,<br>    \"status\": \"online\"<br>}<br><br>message = json.dumps(payload).encode(\"utf-8\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Sockets require strings or bytes\u2014not files.<\/p>\n\n\n\n<h1 id=\"h-common-parameters\" class=\"wp-block-heading\">Common Parameters<\/h1>\n\n\n\n<h2 id=\"h-indent\" class=\"wp-block-heading\">indent<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Pretty prints JSON.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json.dumps(data, indent=4)<\/code><\/pre>\n\n\n\n<h2 id=\"h-sort-keys\" class=\"wp-block-heading\">sort_keys<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Sort dictionary keys alphabetically.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json.dumps(data, sort_keys=True)<\/code><\/pre>\n\n\n\n<h2 id=\"h-ensure-ascii\" class=\"wp-block-heading\">ensure_ascii<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Keep Unicode characters readable.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>data = {\"city\": \"S\u00e3o Paulo\"}<br><br>print(json.dumps(data))<br>print(json.dumps(data, ensure_ascii=False))<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\"city\": \"S\\u00e3o Paulo\"}<br><br>{\"city\": \"S\u00e3o Paulo\"}<\/code><\/pre>\n\n\n\n<h2 id=\"h-default\" class=\"wp-block-heading\">default<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Serialize unsupported objects.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import json<br>from datetime import datetime<br><br>def serializer(obj):<br>    if isinstance(obj, datetime):<br>        return obj.isoformat()<br><br>    raise TypeError()<br><br>data = {<br>    \"created_at\": datetime.now()<br>}<br><br>print(json.dumps(data, default=serializer))<\/code><\/pre>\n\n\n\n<h1 id=\"h-common-mistakes-to-avoid\" class=\"wp-block-heading\">Common Mistakes to Avoid<\/h1>\n\n\n\n<h2 id=\"h-mistake-1-expecting-json-dump-to-return-a-string\" class=\"wp-block-heading\">Mistake 1 \u2013 Expecting json.dump() to Return a String<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u274c Wrong<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>result = json.dump(data, f)<br><br>print(result)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Returns:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>None<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705 Correct<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json.dump(data, f)<br><br>result = json.dumps(data)<\/code><\/pre>\n\n\n\n<h2 id=\"h-mistake-2-passing-a-filename-instead-of-a-file-object\" class=\"wp-block-heading\">Mistake 2 \u2013 Passing a Filename Instead of a File Object<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u274c Wrong<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json.dump(data, \"output.json\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705 Correct<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>with open(\"output.json\", \"w\") as f:<br>    json.dump(data, f)<\/code><\/pre>\n\n\n\n<h2 id=\"h-mistake-3-forgetting-utf-8-encoding\" class=\"wp-block-heading\">Mistake 3 \u2013 Forgetting UTF-8 Encoding<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u274c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>with open(\"data.json\", \"w\") as f:<br>    json.dump(data, f)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>with open(\"data.json\", \"w\", encoding=\"utf-8\") as f:<br>    json.dump(data, f, ensure_ascii=False)<\/code><\/pre>\n\n\n\n<h2 id=\"h-mistake-4-using-json-dump-for-ndjson\" class=\"wp-block-heading\">Mistake 4 \u2013 Using json.dump() for NDJSON<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Correct approach:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>with open(\"log.ndjson\", \"a\") as f:<br>    f.write(json.dumps(record) + \"\\n\")<\/code><\/pre>\n\n\n\n<h1 id=\"h-best-practices\" class=\"wp-block-heading\">Best Practices<\/h1>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Always use <code>with<\/code> blocks when writing files.<\/li>\n\n\n\n<li>Use <code>indent<\/code> only for human-readable JSON.<\/li>\n\n\n\n<li>Use <code>encoding=\"utf-8\"<\/code> with <code>ensure_ascii=False<\/code> for international characters.<\/li>\n\n\n\n<li>Wrap serialization inside <code>try\/except<\/code>.<\/li>\n\n\n\n<li>Use <code>json.dump()<\/code> for large datasets to avoid storing the entire JSON string in memory.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>try:<br>    json_string = json.dumps(data)<br>except TypeError as e:<br>    print(e)<\/code><\/pre>\n\n\n\n<h1 id=\"h-when-should-you-use-which\" class=\"wp-block-heading\">When Should You Use Which?<\/h1>\n\n\n\n<h2 id=\"h-use-json-dumps-when\" class=\"wp-block-heading\">Use json.dumps() When<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You need a JSON string<\/li>\n\n\n\n<li>Sending API responses<\/li>\n\n\n\n<li>Sending data over sockets<\/li>\n\n\n\n<li>Storing JSON in memory<\/li>\n\n\n\n<li>Working with NDJSON<\/li>\n<\/ul>\n\n\n\n<h2 id=\"h-use-json-dump-when\" class=\"wp-block-heading\">Use json.dump() When<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Saving JSON files<\/li>\n\n\n\n<li>Exporting configuration<\/li>\n\n\n\n<li>Writing backups<\/li>\n\n\n\n<li>Exporting reports<\/li>\n\n\n\n<li>Writing large datasets directly to disk<\/li>\n<\/ul>\n\n\n\n<h1 id=\"h-quick-reference-cheat-sheet\" class=\"wp-block-heading\">Quick Reference Cheat Sheet<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>import json<br><br>data = {<br>    \"key\": \"value\",<br>    \"count\": 42<br>}<br><br># json.dumps()<br><br>s = json.dumps(data)<br><br>s = json.dumps(data, indent=4)<br><br>s = json.dumps(data, sort_keys=True)<br><br>s = json.dumps(data, ensure_ascii=False)<br><br># json.dump()<br><br>with open(\"file.json\", \"w\", encoding=\"utf-8\") as f:<br><br>    json.dump(data, f)<br><br>    json.dump(data, f, indent=4)<br><br>    json.dump(data, f, ensure_ascii=False)<br><br># Reading JSON<br><br>s2 = json.loads(s)<br><br>with open(\"file.json\") as f:<br><br>    d2 = json.load(f)<\/code><\/pre>\n\n\n\n<h1 id=\"h-conclusion\" class=\"wp-block-heading\">Conclusion<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">The difference between <strong>json.dump()<\/strong> and <strong>json.dumps()<\/strong> comes down to one simple question:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Need a JSON string?<\/strong> \u2192 Use <strong>json.dumps()<\/strong><\/li>\n\n\n\n<li><strong>Need to save JSON to a file?<\/strong> \u2192 Use <strong>json.dump()<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Both functions are part of Python&#8217;s standard library, require no additional installation, and are widely used in real-world applications.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once you understand this distinction, choosing the right function becomes second nature\u2014whether you&#8217;re building APIs, exporting configuration files, logging structured data, or saving application state. Keep learning with <a href=\"https:\/\/onlinejsonformatter.com\"><strong>Online JSON Formatter<\/strong><\/a>, where you&#8217;ll find practical JSON tutorials and free tools to format, validate, convert, and analyze JSON effortlessly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You&#8217;ve got a Python dictionary. You need to work with JSON. You open the docs, and suddenly you&#8217;re staring at two functions that look almost identical: json.dump() and json.dumps(). Which one should you use? Why do both exist? And what happens if you pick the wrong one? If that sounds familiar, you&#8217;re not alone. This [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":582,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jnews-multi-image_gallery":[],"jnews_single_post":{"format":"standard"},"jnews_primary_category":[],"jnews_override_bookmark_settings":[],"jnews_override_counter":[],"footnotes":""},"categories":[52],"tags":[49,50,51,48,42],"class_list":["post-581","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-json","tag-jsondump","tag-jsondumps","tag-learnpython","tag-pythonjson","tag-pythonprogramming"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v23.6 (Yoast SEO v25.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>json.dump vs json.dumps in Python | Full Guide<\/title>\n<meta name=\"description\" content=\"Learn the difference between json.dump and json.dumps in Python with real-world examples. Know when to write JSON to a file vs convert it to a string.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python json.dump() vs json.dumps() \u2013 Complete Tutorial with Real-World Examples\" \/>\n<meta property=\"og:description\" content=\"Learn the difference between json.dump and json.dumps in Python with real-world examples. Know when to write JSON to a file vs convert it to a string.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/\" \/>\n<meta property=\"og:site_name\" content=\"Online Json Formatter\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-07T18:24:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-07-07T18:24:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/onlinejsonformatter.com\/blog\/wp-content\/uploads\/2026\/07\/Python-json.dump-vs-json.dumps-\u2013-Complete-Tutorial-with-Real-World-Examples.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1717\" \/>\n\t<meta property=\"og:image:height\" content=\"916\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Online JSON Formatter\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Online JSON Formatter\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/\",\"url\":\"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/\",\"name\":\"json.dump vs json.dumps in Python | Full Guide\",\"isPartOf\":{\"@id\":\"https:\/\/onlinejsonformatter.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/onlinejsonformatter.com\/blog\/wp-content\/uploads\/2026\/07\/Python-json.dump-vs-json.dumps-\u2013-Complete-Tutorial-with-Real-World-Examples.png\",\"datePublished\":\"2026-07-07T18:24:28+00:00\",\"dateModified\":\"2026-07-07T18:24:29+00:00\",\"author\":{\"@id\":\"https:\/\/onlinejsonformatter.com\/blog\/#\/schema\/person\/35ae9d5c8ea01b72bb035ab77d41e022\"},\"description\":\"Learn the difference between json.dump and json.dumps in Python with real-world examples. Know when to write JSON to a file vs convert it to a string.\",\"breadcrumb\":{\"@id\":\"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/#primaryimage\",\"url\":\"https:\/\/onlinejsonformatter.com\/blog\/wp-content\/uploads\/2026\/07\/Python-json.dump-vs-json.dumps-\u2013-Complete-Tutorial-with-Real-World-Examples.png\",\"contentUrl\":\"https:\/\/onlinejsonformatter.com\/blog\/wp-content\/uploads\/2026\/07\/Python-json.dump-vs-json.dumps-\u2013-Complete-Tutorial-with-Real-World-Examples.png\",\"width\":1717,\"height\":916,\"caption\":\"json.dump vs json.dumps in Python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/onlinejsonformatter.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python json.dump() vs json.dumps() \u2013 Complete Tutorial with Real-World Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/onlinejsonformatter.com\/blog\/#website\",\"url\":\"https:\/\/onlinejsonformatter.com\/blog\/\",\"name\":\"Online Json Formatter\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/onlinejsonformatter.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/onlinejsonformatter.com\/blog\/#\/schema\/person\/35ae9d5c8ea01b72bb035ab77d41e022\",\"name\":\"Online JSON Formatter\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/onlinejsonformatter.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/77a72da9fb91b18c85e5c0ff36bc4f3f41c97ba4ae4ff22925f5e820e13db9ad?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/77a72da9fb91b18c85e5c0ff36bc4f3f41c97ba4ae4ff22925f5e820e13db9ad?s=96&d=mm&r=g\",\"caption\":\"Online JSON Formatter\"},\"sameAs\":[\"https:\/\/onlinejsonformatter.com\/blog\"],\"url\":\"https:\/\/onlinejsonformatter.com\/blog\/author\/onlinejsonformatter\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"json.dump vs json.dumps in Python | Full Guide","description":"Learn the difference between json.dump and json.dumps in Python with real-world examples. Know when to write JSON to a file vs convert it to a string.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/","og_locale":"en_US","og_type":"article","og_title":"Python json.dump() vs json.dumps() \u2013 Complete Tutorial with Real-World Examples","og_description":"Learn the difference between json.dump and json.dumps in Python with real-world examples. Know when to write JSON to a file vs convert it to a string.","og_url":"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/","og_site_name":"Online Json Formatter","article_published_time":"2026-07-07T18:24:28+00:00","article_modified_time":"2026-07-07T18:24:29+00:00","og_image":[{"width":1717,"height":916,"url":"https:\/\/onlinejsonformatter.com\/blog\/wp-content\/uploads\/2026\/07\/Python-json.dump-vs-json.dumps-\u2013-Complete-Tutorial-with-Real-World-Examples.png","type":"image\/png"}],"author":"Online JSON Formatter","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Online JSON Formatter","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/","url":"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/","name":"json.dump vs json.dumps in Python | Full Guide","isPartOf":{"@id":"https:\/\/onlinejsonformatter.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/#primaryimage"},"image":{"@id":"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/#primaryimage"},"thumbnailUrl":"https:\/\/onlinejsonformatter.com\/blog\/wp-content\/uploads\/2026\/07\/Python-json.dump-vs-json.dumps-\u2013-Complete-Tutorial-with-Real-World-Examples.png","datePublished":"2026-07-07T18:24:28+00:00","dateModified":"2026-07-07T18:24:29+00:00","author":{"@id":"https:\/\/onlinejsonformatter.com\/blog\/#\/schema\/person\/35ae9d5c8ea01b72bb035ab77d41e022"},"description":"Learn the difference between json.dump and json.dumps in Python with real-world examples. Know when to write JSON to a file vs convert it to a string.","breadcrumb":{"@id":"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/#primaryimage","url":"https:\/\/onlinejsonformatter.com\/blog\/wp-content\/uploads\/2026\/07\/Python-json.dump-vs-json.dumps-\u2013-Complete-Tutorial-with-Real-World-Examples.png","contentUrl":"https:\/\/onlinejsonformatter.com\/blog\/wp-content\/uploads\/2026\/07\/Python-json.dump-vs-json.dumps-\u2013-Complete-Tutorial-with-Real-World-Examples.png","width":1717,"height":916,"caption":"json.dump vs json.dumps in Python"},{"@type":"BreadcrumbList","@id":"https:\/\/onlinejsonformatter.com\/blog\/python-json-dump-vs-json-dumps-complete-tutorial-with-real-world-examples\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/onlinejsonformatter.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python json.dump() vs json.dumps() \u2013 Complete Tutorial with Real-World Examples"}]},{"@type":"WebSite","@id":"https:\/\/onlinejsonformatter.com\/blog\/#website","url":"https:\/\/onlinejsonformatter.com\/blog\/","name":"Online Json Formatter","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/onlinejsonformatter.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/onlinejsonformatter.com\/blog\/#\/schema\/person\/35ae9d5c8ea01b72bb035ab77d41e022","name":"Online JSON Formatter","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/onlinejsonformatter.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/77a72da9fb91b18c85e5c0ff36bc4f3f41c97ba4ae4ff22925f5e820e13db9ad?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/77a72da9fb91b18c85e5c0ff36bc4f3f41c97ba4ae4ff22925f5e820e13db9ad?s=96&d=mm&r=g","caption":"Online JSON Formatter"},"sameAs":["https:\/\/onlinejsonformatter.com\/blog"],"url":"https:\/\/onlinejsonformatter.com\/blog\/author\/onlinejsonformatter\/"}]}},"_links":{"self":[{"href":"https:\/\/onlinejsonformatter.com\/blog\/wp-json\/wp\/v2\/posts\/581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/onlinejsonformatter.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/onlinejsonformatter.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/onlinejsonformatter.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/onlinejsonformatter.com\/blog\/wp-json\/wp\/v2\/comments?post=581"}],"version-history":[{"count":2,"href":"https:\/\/onlinejsonformatter.com\/blog\/wp-json\/wp\/v2\/posts\/581\/revisions"}],"predecessor-version":[{"id":584,"href":"https:\/\/onlinejsonformatter.com\/blog\/wp-json\/wp\/v2\/posts\/581\/revisions\/584"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/onlinejsonformatter.com\/blog\/wp-json\/wp\/v2\/media\/582"}],"wp:attachment":[{"href":"https:\/\/onlinejsonformatter.com\/blog\/wp-json\/wp\/v2\/media?parent=581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/onlinejsonformatter.com\/blog\/wp-json\/wp\/v2\/categories?post=581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/onlinejsonformatter.com\/blog\/wp-json\/wp\/v2\/tags?post=581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}