From 2050232473ece817838770d9fa2e9c773d546249 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Wed, 19 Aug 2009 01:38:56 -0400 Subject: [PATCH] finished #json-unknown-types --- serializing.html | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/serializing.html b/serializing.html index b5ba159..2dd3fe6 100644 --- a/serializing.html +++ b/serializing.html @@ -505,7 +505,7 @@ def to_json(python_object):
  • If so, we’ll do something similar to the conversion we did with the bytes object: convert the time.struct_time object to a dictionary that only contains JSON-serializable values. In this case, the easiest way to convert a datetime into a JSON-serializable value is to convert it to a string with the time.asctime() function. The time.asctime() function will convert that nasty-looking time.struct_time into the string 'Fri Mar 27 22:20:42 2009'. -

    +

    With these two custom conversions, the entire entry data structure should serialize to JSON without any further problems.

     >>> shell
    @@ -513,11 +513,6 @@ def to_json(python_object):
     >>> with open('entry.json', 'w', encoding='utf-8') as f:
     ...     json.dump(entry, default=customserializer.to_json)
     ... 
    -
      -
    1. FIXME -
    - -

    FIXME

     you@localhost:~/diveintopython3/examples$ ls -l example.json
    @@ -528,9 +523,8 @@ def to_json(python_object):
     "tags": ["diveintopython", "docbook", "html"], "title": "Dive into history, 2009 edition",
     "article_link": "http://diveintomark.org/archives/2009/03/27/dive-into-history-2009-edition",
     "published": true}
    -
      -
    1. FIXME -
    + +

    Loading Data from a JSON File

    FIXME