-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.html
2098 lines (1953 loc) · 196 KB
/
api.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html class="no-js" lang="en" data-content_root="./">
<head><meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<meta name="color-scheme" content="light dark"><meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" /><link rel="next" title="jsonpickle extensions" href="extensions.html" /><link rel="prev" title="jsonpickle Documentation" href="index.html" />
<!-- Generated with Sphinx 8.1.2 and Furo 2024.08.06 -->
<title>jsonpickle API - jsonpickle documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=a746c00c" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?v=354aac6f" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo-extensions.css?v=302659d7" />
<style>
body {
--color-code-background: #f8f8f8;
--color-code-foreground: black;
}
@media not print {
body[data-theme="dark"] {
--color-code-background: #202020;
--color-code-foreground: #d0d0d0;
}
@media (prefers-color-scheme: dark) {
body:not([data-theme="light"]) {
--color-code-background: #202020;
--color-code-foreground: #d0d0d0;
}
}
}
</style></head>
<body>
<script>
document.body.dataset.theme = localStorage.getItem("theme") || "auto";
</script>
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<symbol id="svg-toc" viewBox="0 0 24 24">
<title>Contents</title>
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 1024 1024">
<path d="M408 442h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm-8 204c0 4.4 3.6 8 8 8h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56zm504-486H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 632H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM115.4 518.9L271.7 642c5.8 4.6 14.4.5 14.4-6.9V388.9c0-7.4-8.5-11.5-14.4-6.9L115.4 505.1a8.74 8.74 0 0 0 0 13.8z"/>
</svg>
</symbol>
<symbol id="svg-menu" viewBox="0 0 24 24">
<title>Menu</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-menu">
<line x1="3" y1="12" x2="21" y2="12"></line>
<line x1="3" y1="6" x2="21" y2="6"></line>
<line x1="3" y1="18" x2="21" y2="18"></line>
</svg>
</symbol>
<symbol id="svg-arrow-right" viewBox="0 0 24 24">
<title>Expand</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-chevron-right">
<polyline points="9 18 15 12 9 6"></polyline>
</svg>
</symbol>
<symbol id="svg-sun" viewBox="0 0 24 24">
<title>Light mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="feather-sun">
<circle cx="12" cy="12" r="5"></circle>
<line x1="12" y1="1" x2="12" y2="3"></line>
<line x1="12" y1="21" x2="12" y2="23"></line>
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
<line x1="1" y1="12" x2="3" y2="12"></line>
<line x1="21" y1="12" x2="23" y2="12"></line>
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
</svg>
</symbol>
<symbol id="svg-moon" viewBox="0 0 24 24">
<title>Dark mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-moon">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z" />
</svg>
</symbol>
<symbol id="svg-sun-with-moon" viewBox="0 0 24 24">
<title>Auto light/dark, in light mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1" stroke-linecap="round" stroke-linejoin="round"
class="icon-custom-derived-from-feather-sun-and-tabler-moon">
<path style="opacity: 50%" d="M 5.411 14.504 C 5.471 14.504 5.532 14.504 5.591 14.504 C 3.639 16.319 4.383 19.569 6.931 20.352 C 7.693 20.586 8.512 20.551 9.25 20.252 C 8.023 23.207 4.056 23.725 2.11 21.184 C 0.166 18.642 1.702 14.949 4.874 14.536 C 5.051 14.512 5.231 14.5 5.411 14.5 L 5.411 14.504 Z"/>
<line x1="14.5" y1="3.25" x2="14.5" y2="1.25"/>
<line x1="14.5" y1="15.85" x2="14.5" y2="17.85"/>
<line x1="10.044" y1="5.094" x2="8.63" y2="3.68"/>
<line x1="19" y1="14.05" x2="20.414" y2="15.464"/>
<line x1="8.2" y1="9.55" x2="6.2" y2="9.55"/>
<line x1="20.8" y1="9.55" x2="22.8" y2="9.55"/>
<line x1="10.044" y1="14.006" x2="8.63" y2="15.42"/>
<line x1="19" y1="5.05" x2="20.414" y2="3.636"/>
<circle cx="14.5" cy="9.55" r="3.6"/>
</svg>
</symbol>
<symbol id="svg-moon-with-sun" viewBox="0 0 24 24">
<title>Auto light/dark, in dark mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1" stroke-linecap="round" stroke-linejoin="round"
class="icon-custom-derived-from-feather-sun-and-tabler-moon">
<path d="M 8.282 7.007 C 8.385 7.007 8.494 7.007 8.595 7.007 C 5.18 10.184 6.481 15.869 10.942 17.24 C 12.275 17.648 13.706 17.589 15 17.066 C 12.851 22.236 5.91 23.143 2.505 18.696 C -0.897 14.249 1.791 7.786 7.342 7.063 C 7.652 7.021 7.965 7 8.282 7 L 8.282 7.007 Z"/>
<line style="opacity: 50%" x1="18" y1="3.705" x2="18" y2="2.5"/>
<line style="opacity: 50%" x1="18" y1="11.295" x2="18" y2="12.5"/>
<line style="opacity: 50%" x1="15.316" y1="4.816" x2="14.464" y2="3.964"/>
<line style="opacity: 50%" x1="20.711" y1="10.212" x2="21.563" y2="11.063"/>
<line style="opacity: 50%" x1="14.205" y1="7.5" x2="13.001" y2="7.5"/>
<line style="opacity: 50%" x1="21.795" y1="7.5" x2="23" y2="7.5"/>
<line style="opacity: 50%" x1="15.316" y1="10.184" x2="14.464" y2="11.036"/>
<line style="opacity: 50%" x1="20.711" y1="4.789" x2="21.563" y2="3.937"/>
<circle style="opacity: 50%" cx="18" cy="7.5" r="2.169"/>
</svg>
</symbol>
<symbol id="svg-pencil" viewBox="0 0 24 24">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-pencil-code">
<path d="M4 20h4l10.5 -10.5a2.828 2.828 0 1 0 -4 -4l-10.5 10.5v4" />
<path d="M13.5 6.5l4 4" />
<path d="M20 21l2 -2l-2 -2" />
<path d="M17 17l-2 2l2 2" />
</svg>
</symbol>
<symbol id="svg-eye" viewBox="0 0 24 24">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-eye-code">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0" />
<path
d="M11.11 17.958c-3.209 -.307 -5.91 -2.293 -8.11 -5.958c2.4 -4 5.4 -6 9 -6c3.6 0 6.6 2 9 6c-.21 .352 -.427 .688 -.647 1.008" />
<path d="M20 21l2 -2l-2 -2" />
<path d="M17 17l-2 2l2 2" />
</svg>
</symbol>
</svg>
<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation">
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc">
<label class="overlay sidebar-overlay" for="__navigation">
<div class="visually-hidden">Hide navigation sidebar</div>
</label>
<label class="overlay toc-overlay" for="__toc">
<div class="visually-hidden">Hide table of contents sidebar</div>
</label>
<a class="skip-to-content muted-link" href="#furo-main-content">Skip to content</a>
<div class="page">
<header class="mobile-header">
<div class="header-left">
<label class="nav-overlay-icon" for="__navigation">
<div class="visually-hidden">Toggle site navigation sidebar</div>
<i class="icon"><svg><use href="#svg-menu"></use></svg></i>
</label>
</div>
<div class="header-center">
<a href="index.html"><div class="brand">jsonpickle documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
<button class="theme-toggle">
<div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
<svg class="theme-icon-when-auto-light"><use href="#svg-sun-with-moon"></use></svg>
<svg class="theme-icon-when-auto-dark"><use href="#svg-moon-with-sun"></use></svg>
<svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
<svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
</button>
</div>
<label class="toc-overlay-icon toc-header-icon" for="__toc">
<div class="visually-hidden">Toggle table of contents sidebar</div>
<i class="icon"><svg><use href="#svg-toc"></use></svg></i>
</label>
</div>
</header>
<aside class="sidebar-drawer">
<div class="sidebar-container">
<div class="sidebar-sticky"><a class="sidebar-brand" href="index.html">
<span class="sidebar-brand-text">jsonpickle documentation</span>
</a><form class="sidebar-search-container" method="get" action="search.html" role="search">
<input class="sidebar-search" placeholder="Search" name="q" aria-label="Search">
<input type="hidden" name="check_keywords" value="yes">
<input type="hidden" name="area" value="default">
</form>
<div id="searchbox"></div><div class="sidebar-scroll"><div class="sidebar-tree">
<ul class="current">
<li class="toctree-l1 current current-page"><a class="current reference internal" href="#">jsonpickle API</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="extensions.html">jsonpickle extensions</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="contrib.html">Contributing to jsonpickle</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="history.html">History</a></li>
</ul>
</div>
</div>
</div>
</div>
</aside>
<div class="main">
<div class="content">
<div class="article-container">
<a href="#" class="back-to-top muted-link">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12z"></path>
</svg>
<span>Back to top</span>
</a>
<div class="content-icon-container">
<div class="view-this-page">
<a class="muted-link" href="_sources/api.rst.txt" title="View this page">
<svg><use href="#svg-eye"></use></svg>
<span class="visually-hidden">View this page</span>
</a>
</div>
<div class="theme-toggle-container theme-toggle-content">
<button class="theme-toggle">
<div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
<svg class="theme-icon-when-auto-light"><use href="#svg-sun-with-moon"></use></svg>
<svg class="theme-icon-when-auto-dark"><use href="#svg-moon-with-sun"></use></svg>
<svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
<svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
</button>
</div>
<label class="toc-overlay-icon toc-content-icon" for="__toc">
<div class="visually-hidden">Toggle table of contents sidebar</div>
<i class="icon"><svg><use href="#svg-toc"></use></svg></i>
</label>
</div>
<article role="main" id="furo-main-content">
<section id="jsonpickle-api">
<span id="id1"></span><h1><a class="toc-backref" href="#id2" role="doc-backlink">jsonpickle API</a><a class="headerlink" href="#jsonpickle-api" title="Link to this heading">¶</a></h1>
<nav class="contents" id="contents">
<p class="topic-title">Contents</p>
<ul class="simple">
<li><p><a class="reference internal" href="#jsonpickle-api" id="id2">jsonpickle API</a></p>
<ul>
<li><p><a class="reference internal" href="#jsonpickle-high-level-api" id="id3"><a class="reference internal" href="index.html#module-jsonpickle" title="jsonpickle"><code class="xref py py-mod docutils literal notranslate"><span class="pre">jsonpickle</span></code></a> – High Level API</a></p>
<ul>
<li><p><a class="reference internal" href="#choosing-and-loading-backends" id="id4">Choosing and Loading Backends</a></p></li>
<li><p><a class="reference internal" href="#customizing-json-output" id="id5">Customizing JSON output</a></p></li>
<li><p><a class="reference internal" href="#jsonpickle-handlers-custom-serialization-handlers" id="id6"><a class="reference internal" href="#module-jsonpickle.handlers" title="jsonpickle.handlers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">jsonpickle.handlers</span></code></a> – Custom Serialization Handlers</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#low-level-api" id="id7">Low Level API</a></p>
<ul>
<li><p><a class="reference internal" href="#module-jsonpickle.pickler" id="id8"><a class="reference internal" href="#module-jsonpickle.pickler" title="jsonpickle.pickler"><code class="xref py py-mod docutils literal notranslate"><span class="pre">jsonpickle.pickler</span></code></a> – Python to JSON-compatible dict</a></p></li>
<li><p><a class="reference internal" href="#module-jsonpickle.unpickler" id="id9"><a class="reference internal" href="#module-jsonpickle.unpickler" title="jsonpickle.unpickler"><code class="xref py py-mod docutils literal notranslate"><span class="pre">jsonpickle.unpickler</span></code></a> – JSON-compatible dict to Python</a></p></li>
<li><p><a class="reference internal" href="#module-jsonpickle.backend" id="id10"><a class="reference internal" href="#module-jsonpickle.backend" title="jsonpickle.backend"><code class="xref py py-mod docutils literal notranslate"><span class="pre">jsonpickle.backend</span></code></a> – JSON Backend Management</a></p></li>
<li><p><a class="reference internal" href="#module-jsonpickle.util" id="id11"><a class="reference internal" href="#module-jsonpickle.util" title="jsonpickle.util"><code class="xref py py-mod docutils literal notranslate"><span class="pre">jsonpickle.util</span></code></a> – Helper functions</a></p></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
<section id="jsonpickle-high-level-api">
<span id="api-docs"></span><h2><a class="toc-backref" href="#id3" role="doc-backlink"><a class="reference internal" href="index.html#module-jsonpickle" title="jsonpickle"><code class="xref py py-mod docutils literal notranslate"><span class="pre">jsonpickle</span></code></a> – High Level API</a><a class="headerlink" href="#jsonpickle-high-level-api" title="Link to this heading">¶</a></h2>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>For performance and compatibility reasons, jsonpickle does not preserve
non-string dictionary keys by default. This results in a simpler, but
sometimes lossy, JSON representation.</p>
<p>Specify <code class="docutils literal notranslate"><span class="pre">keys=True</span></code> when encoding and decoding to preserve integers,
tuples, and other non-strings types as dictionary keys.</p>
</div>
<dl class="py function">
<dt class="sig sig-object py" id="jsonpickle.encode">
<span class="sig-prename descclassname"><span class="pre">jsonpickle.</span></span><span class="sig-name descname"><span class="pre">encode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">unpicklable</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">make_refs</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">keys</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_depth</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">reset</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">backend</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">warn</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">context</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_iter</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">use_decimal</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">numeric_keys</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">use_base85</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fail_safe</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">indent</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">separators</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">include_properties</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">handle_readonly</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.encode" title="Link to this definition">¶</a></dt>
<dd><p>Return a JSON formatted representation of value, a Python object.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>unpicklable</strong> – <p>If set to <code class="docutils literal notranslate"><span class="pre">False</span></code> then the output will not contain the
information necessary to turn the JSON data back into Python objects,
but a simpler JSON stream is produced. It’s recommended to set this
parameter to <code class="docutils literal notranslate"><span class="pre">False</span></code> when your code does not rely on two objects
having the same <code class="docutils literal notranslate"><span class="pre">id()</span></code> value, and when it is sufficient for those two
objects to be equal by <code class="docutils literal notranslate"><span class="pre">==</span></code>, such as when serializing sklearn
instances. If you experience (de)serialization being incorrect when you
use numpy, pandas, or sklearn handlers, this should be set to <code class="docutils literal notranslate"><span class="pre">False</span></code>.
If you want the output to not include the dtype for numpy arrays, add:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">jsonpickle</span><span class="o">.</span><span class="n">register</span><span class="p">(</span>
<span class="n">numpy</span><span class="o">.</span><span class="n">generic</span><span class="p">,</span> <span class="n">UnpicklableNumpyGenericHandler</span><span class="p">,</span> <span class="n">base</span><span class="o">=</span><span class="kc">True</span>
<span class="p">)</span>
</pre></div>
</div>
<p>before your pickling code.</p>
</p></li>
<li><p><strong>make_refs</strong> – If set to False jsonpickle’s referencing support is
disabled. Objects that are id()-identical won’t be preserved across
encode()/decode(), but the resulting JSON stream will be conceptually
simpler. jsonpickle detects cyclical objects and will break the cycle
by calling repr() instead of recursing when make_refs is set False.</p></li>
<li><p><strong>keys</strong> – If set to True then jsonpickle will encode non-string
dictionary keys instead of coercing them into strings via <cite>repr()</cite>.
This is typically what you want if you need to support Integer or
objects as dictionary keys.</p></li>
<li><p><strong>max_depth</strong> – If set to a non-negative integer then jsonpickle will
not recurse deeper than ‘max_depth’ steps into the object. Anything
deeper than ‘max_depth’ is represented using a Python repr() of the
object.</p></li>
<li><p><strong>reset</strong> – Custom pickle handlers that use the <cite>Pickler.flatten</cite> method or
<cite>jsonpickle.encode</cite> function must call <cite>encode</cite> with <cite>reset=False</cite>
in order to retain object references during pickling.
This flag is not typically used outside of a custom handler or
<cite>__getstate__</cite> implementation.</p></li>
<li><p><strong>backend</strong> – If set to an instance of jsonpickle.backend.JSONBackend,
jsonpickle will use that backend for deserialization.</p></li>
<li><p><strong>warn</strong> – If set to True then jsonpickle will warn when it
returns None for an object which it cannot pickle
(e.g. file descriptors).</p></li>
<li><p><strong>context</strong> – Supply a pre-built Pickler or Unpickler object to the
<cite>jsonpickle.encode</cite> and <cite>jsonpickle.decode</cite> machinery instead
of creating a new instance. The <cite>context</cite> represents the currently
active Pickler and Unpickler objects when custom handlers are
invoked by jsonpickle.</p></li>
<li><p><strong>max_iter</strong> – If set to a non-negative integer then jsonpickle will
consume at most <cite>max_iter</cite> items when pickling iterators.</p></li>
<li><p><strong>use_decimal</strong> – <p>If set to True jsonpickle will allow Decimal
instances to pass-through, with the assumption that the simplejson
backend will be used in <cite>use_decimal</cite> mode. In order to use this mode
you will need to configure simplejson:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">jsonpickle</span><span class="o">.</span><span class="n">set_encoder_options</span><span class="p">(</span><span class="s1">'simplejson'</span><span class="p">,</span>
<span class="n">use_decimal</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">sort_keys</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">jsonpickle</span><span class="o">.</span><span class="n">set_decoder_options</span><span class="p">(</span><span class="s1">'simplejson'</span><span class="p">,</span>
<span class="n">use_decimal</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">jsonpickle</span><span class="o">.</span><span class="n">set_preferred_backend</span><span class="p">(</span><span class="s1">'simplejson'</span><span class="p">)</span>
</pre></div>
</div>
<p>NOTE: A side-effect of the above settings is that float values will be
converted to Decimal when converting to json.</p>
</p></li>
<li><p><strong>numeric_keys</strong> – Only use this option if the backend supports integer
dict keys natively. This flag tells jsonpickle to leave numeric keys
as-is rather than conforming them to json-friendly strings.
Using <code class="docutils literal notranslate"><span class="pre">keys=True</span></code> is the typical solution for integer keys, so only
use this if you have a specific use case where you want to allow the
backend to handle serialization of numeric dict keys.</p></li>
<li><p><strong>use_base85</strong> – If possible, use base85 to encode binary data. Base85 bloats binary data
by 1/4 as opposed to base64, which expands it by 1/3. This argument is
ignored on Python 2 because it doesn’t support it.</p></li>
<li><p><strong>fail_safe</strong> – If set to a function exceptions are ignored when pickling
and if a exception happens the function is called and the return value
is used as the value for the object that caused the error</p></li>
<li><p><strong>indent</strong> – When <cite>indent</cite> is a non-negative integer, then JSON array
elements and object members will be pretty-printed with that indent
level. An indent level of 0 will only insert newlines. <code class="docutils literal notranslate"><span class="pre">None</span></code> is
the most compact representation. Since the default item separator is
<code class="docutils literal notranslate"><span class="pre">(',</span> <span class="pre">',</span> <span class="pre">':</span> <span class="pre">')</span></code>, the output might include trailing whitespace when
<code class="docutils literal notranslate"><span class="pre">indent</span></code> is specified. You can use <code class="docutils literal notranslate"><span class="pre">separators=(',',</span> <span class="pre">':</span> <span class="pre">')</span></code> to
avoid this. This value is passed directly to the active JSON backend
library and not used by jsonpickle directly.</p></li>
<li><p><strong>separators</strong> – If <code class="docutils literal notranslate"><span class="pre">separators</span></code> is an <code class="docutils literal notranslate"><span class="pre">(item_separator,</span> <span class="pre">dict_separator)</span></code> tuple
then it will be used instead of the default <code class="docutils literal notranslate"><span class="pre">(',</span> <span class="pre">',</span> <span class="pre">':</span> <span class="pre">')</span></code>
separators. <code class="docutils literal notranslate"><span class="pre">(',',</span> <span class="pre">':')</span></code> is the most compact JSON representation.
This value is passed directly to the active JSON backend library and
not used by jsonpickle directly.</p></li>
<li><p><strong>include_properties</strong> – Include the names and values of class properties in the generated json.
Properties are unpickled properly regardless of this setting, this is
meant to be used if processing the json outside of Python. Certain types
such as sets will not pickle due to not having a native-json equivalent.
Defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p></li>
<li><p><strong>handle_readonly</strong> – Handle objects with readonly methods, such as Django’s SafeString. This
basically prevents jsonpickle from raising an exception for such objects.
You MUST set <code class="docutils literal notranslate"><span class="pre">handle_readonly=True</span></code> for the decoding if you encode with
this flag set to <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p></li>
</ul>
</dd>
</dl>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">encode</span><span class="p">(</span><span class="s1">'my string'</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'"my string"'</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="n">encode</span><span class="p">(</span><span class="mi">36</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'36'</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="n">encode</span><span class="p">({</span><span class="s1">'foo'</span><span class="p">:</span> <span class="kc">True</span><span class="p">})</span> <span class="o">==</span> <span class="s1">'{"foo": true}'</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="n">encode</span><span class="p">({</span><span class="s1">'foo'</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]]},</span> <span class="n">max_depth</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="go">'{"foo": "[1, 2, [3, 4]]"}'</span>
</pre></div>
</div>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="jsonpickle.decode">
<span class="sig-prename descclassname"><span class="pre">jsonpickle.</span></span><span class="sig-name descname"><span class="pre">decode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">string</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">backend</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">context</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">keys</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">reset</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">safe</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">classes</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">v1_decode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">on_missing</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'ignore'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">handle_readonly</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.decode" title="Link to this definition">¶</a></dt>
<dd><p>Convert a JSON string into a Python object.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>backend</strong> – If set to an instance of jsonpickle.backend.JSONBackend, jsonpickle
will use that backend for deserialization.</p></li>
<li><p><strong>context</strong> – Supply a pre-built Pickler or Unpickler object to the
<cite>jsonpickle.encode</cite> and <cite>jsonpickle.decode</cite> machinery instead
of creating a new instance. The <cite>context</cite> represents the currently
active Pickler and Unpickler objects when custom handlers are
invoked by jsonpickle.</p></li>
<li><p><strong>keys</strong> – If set to True then jsonpickle will decode non-string dictionary keys
into python objects via the jsonpickle protocol.</p></li>
<li><p><strong>reset</strong> – Custom pickle handlers that use the <cite>Pickler.flatten</cite> method or
<cite>jsonpickle.encode</cite> function must call <cite>encode</cite> with <cite>reset=False</cite>
in order to retain object references during pickling.
This flag is not typically used outside of a custom handler or
<cite>__getstate__</cite> implementation.</p></li>
<li><p><strong>safe</strong> – <p>If set to <code class="docutils literal notranslate"><span class="pre">False</span></code>, use of <code class="docutils literal notranslate"><span class="pre">eval()</span></code> for backwards-compatible (pre-0.7.0)
deserialization of repr-serialized objects is enabled. Defaults to <code class="docutils literal notranslate"><span class="pre">True</span></code>.
The default value was <code class="docutils literal notranslate"><span class="pre">False</span></code> in jsonpickle v3 and changed to <code class="docutils literal notranslate"><span class="pre">True</span></code> in jsonpickle v4.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p><code class="docutils literal notranslate"><span class="pre">eval()</span></code> is used when set to <code class="docutils literal notranslate"><span class="pre">False</span></code> and is not secure against
malicious inputs. You should avoid setting <code class="docutils literal notranslate"><span class="pre">safe=False</span></code>.</p>
</div>
</p></li>
<li><p><strong>classes</strong> – If set to a single class, or a sequence (list, set, tuple) of
classes, then the classes will be made available when constructing objects.
If set to a dictionary of class names to class objects, the class object
will be provided to jsonpickle to deserialize the class name into.
This can be used to give jsonpickle access to local classes that are not
available through the global module import scope, and the dict method can
be used to deserialize encoded objects into a new class.</p></li>
<li><p><strong>v1_decode</strong> – If set to True it enables you to decode objects serialized in
jsonpickle v1. Please do not attempt to re-encode the objects in the v1 format!
Version 2’s format fixes issue #255, and allows dictionary identity to be
preserved through an encode/decode cycle.</p></li>
<li><p><strong>on_missing</strong> – If set to ‘error’, it will raise an error if the class it’s
decoding is not found. If set to ‘warn’, it will warn you in said case.
If set to a non-awaitable function, it will call said callback function
with the class name (a string) as the only parameter. Strings passed to
<cite>on_missing</cite> are lowercased automatically.</p></li>
<li><p><strong>handle_readonly</strong> – If set to True, the Unpickler will handle objects encoded
with ‘handle_readonly’ properly. Do not set this flag for objects not encoded
with ‘handle_readonly’ set to True.</p></li>
</ul>
</dd>
</dl>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">decode</span><span class="p">(</span><span class="s1">'"my string"'</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'my string'</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="n">decode</span><span class="p">(</span><span class="s1">'36'</span><span class="p">)</span>
<span class="go">36</span>
</pre></div>
</div>
</dd></dl>
<section id="choosing-and-loading-backends">
<h3><a class="toc-backref" href="#id4" role="doc-backlink">Choosing and Loading Backends</a><a class="headerlink" href="#choosing-and-loading-backends" title="Link to this heading">¶</a></h3>
<p>jsonpickle allows the user to specify what JSON backend to use
when encoding and decoding. By default, jsonpickle will try to use, in
the following order: <code class="docutils literal notranslate"><span class="pre">simplejson</span></code> and <a class="reference external" href="https://docs.python.org/3/library/json.html#module-json" title="(in Python v3.13)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">json</span></code></a>.
The preferred backend can be set via <a class="reference internal" href="#jsonpickle.set_preferred_backend" title="jsonpickle.set_preferred_backend"><code class="xref py py-func docutils literal notranslate"><span class="pre">jsonpickle.set_preferred_backend()</span></code></a>.
Additional JSON backends can be used via <a class="reference internal" href="#jsonpickle.load_backend" title="jsonpickle.load_backend"><code class="xref py py-func docutils literal notranslate"><span class="pre">jsonpickle.load_backend()</span></code></a>.</p>
<p>For example, users of <a class="reference external" href="http://www.djangoproject.com/">Django</a> can use the
version of simplejson that is bundled in Django:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">jsonpickle</span><span class="o">.</span><span class="n">load_backend</span><span class="p">(</span><span class="s1">'django.util.simplejson'</span><span class="p">,</span> <span class="s1">'dumps'</span><span class="p">,</span> <span class="s1">'loads'</span><span class="p">,</span> <span class="ne">ValueError</span><span class="p">))</span>
<span class="n">jsonpickle</span><span class="o">.</span><span class="n">set_preferred_backend</span><span class="p">(</span><span class="s1">'django.util.simplejson'</span><span class="p">)</span>
</pre></div>
</div>
<p>Supported backends:</p>
<blockquote>
<div><ul class="simple">
<li><p><a class="reference external" href="https://docs.python.org/3/library/json.html#module-json" title="(in Python v3.13)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">json</span></code></a></p></li>
<li><p><a class="reference external" href="http://undefined.org/python/#simplejson">simplejson</a></p></li>
</ul>
</div></blockquote>
<p>Experimental backends:</p>
<blockquote>
<div><ul class="simple">
<li><p><a class="reference external" href="https://pypi.org/project/jsonlib/">jsonlib</a></p></li>
<li><p>yajl via <a class="reference external" href="https://github.com/rtyler/py-yajl/">py-yajl</a></p></li>
<li><p><a class="reference external" href="https://pypi.org/project/ujson/">ujson</a></p></li>
</ul>
</div></blockquote>
<dl class="py function">
<dt class="sig sig-object py" id="jsonpickle.set_preferred_backend">
<span class="sig-prename descclassname"><span class="pre">jsonpickle.</span></span><span class="sig-name descname"><span class="pre">set_preferred_backend</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.set_preferred_backend" title="Link to this definition">¶</a></dt>
<dd><p>Set the preferred json backend.</p>
<p>If a preferred backend is set then jsonpickle tries to use it
before any other backend.</p>
<p>For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">set_preferred_backend</span><span class="p">(</span><span class="s1">'simplejson'</span><span class="p">)</span>
</pre></div>
</div>
<p>If the backend is not one of the built-in jsonpickle backends
(json/simplejson) then you must load the backend
prior to calling set_preferred_backend.</p>
<p>AssertionError is raised if the backend has not been loaded.</p>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="jsonpickle.load_backend">
<span class="sig-prename descclassname"><span class="pre">jsonpickle.</span></span><span class="sig-name descname"><span class="pre">load_backend</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dumps</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'dumps'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">loads</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'loads'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">loads_exc</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">ValueError</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.load_backend" title="Link to this definition">¶</a></dt>
<dd><p>Load a JSON backend by name.</p>
<p>This method loads a backend and sets up references to that
backend’s loads/dumps functions and exception classes.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>dumps</strong> – is the name of the backend’s encode method.
The method should take an object and return a string.
Defaults to ‘dumps’.</p></li>
<li><p><strong>loads</strong> – names the backend’s method for the reverse
operation – returning a Python object from a string.</p></li>
<li><p><strong>loads_exc</strong> – can be either the name of the exception class
used to denote decoding errors, or it can be a direct reference
to the appropriate exception class itself. If it is a name,
then the assumption is that an exception class of that name
can be found in the backend module’s namespace.</p></li>
<li><p><strong>load</strong> – names the backend’s ‘load’ method.</p></li>
<li><p><strong>dump</strong> – names the backend’s ‘dump’ method.</p></li>
</ul>
</dd>
<dt class="field-even">Rtype bool<span class="colon">:</span></dt>
<dd class="field-even"><p>True on success, False if the backend could not be loaded.</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="jsonpickle.remove_backend">
<span class="sig-prename descclassname"><span class="pre">jsonpickle.</span></span><span class="sig-name descname"><span class="pre">remove_backend</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.remove_backend" title="Link to this definition">¶</a></dt>
<dd><p>Remove all entries for a particular backend.</p>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="jsonpickle.set_encoder_options">
<span class="sig-prename descclassname"><span class="pre">jsonpickle.</span></span><span class="sig-name descname"><span class="pre">set_encoder_options</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.set_encoder_options" title="Link to this definition">¶</a></dt>
<dd><p>Associate encoder-specific options with an encoder.</p>
<p>After calling set_encoder_options, any calls to jsonpickle’s
encode method will pass the supplied args and kwargs along to
the appropriate backend’s encode method.</p>
<p>For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">set_encoder_options</span><span class="p">(</span><span class="s1">'simplejson'</span><span class="p">,</span> <span class="n">sort_keys</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
</pre></div>
</div>
<p>See the appropriate encoder’s documentation for details about
the supported arguments and keyword arguments.</p>
<p>WARNING: If you pass sort_keys=True, and the object to encode
contains <code class="docutils literal notranslate"><span class="pre">__slots__</span></code>, and you set <code class="docutils literal notranslate"><span class="pre">warn</span></code> to True,
a TypeError will be raised!</p>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="jsonpickle.set_decoder_options">
<span class="sig-prename descclassname"><span class="pre">jsonpickle.</span></span><span class="sig-name descname"><span class="pre">set_decoder_options</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.set_decoder_options" title="Link to this definition">¶</a></dt>
<dd><p>Associate decoder-specific options with a decoder.</p>
<p>After calling set_decoder_options, any calls to jsonpickle’s
decode method will pass the supplied args and kwargs along to
the appropriate backend’s decode method.</p>
<p>For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">set_decoder_options</span><span class="p">(</span><span class="s1">'simplejson'</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s1">'utf8'</span><span class="p">,</span> <span class="bp">cls</span><span class="o">=</span><span class="n">JSONDecoder</span><span class="p">)</span>
</pre></div>
</div>
<p>See the appropriate decoder’s documentation for details about
the supported arguments and keyword arguments.</p>
</dd></dl>
</section>
<section id="customizing-json-output">
<h3><a class="toc-backref" href="#id5" role="doc-backlink">Customizing JSON output</a><a class="headerlink" href="#customizing-json-output" title="Link to this heading">¶</a></h3>
<p>jsonpickle supports the standard <a class="reference external" href="https://docs.python.org/3/library/pickle.html#module-pickle" title="(in Python v3.13)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> <cite>__getstate__</cite> and <cite>__setstate__</cite>
protocol for representing object instances.</p>
<dl class="py method">
<dt class="sig sig-object py" id="object.__getstate__">
<span class="sig-prename descclassname"><span class="pre">object.</span></span><span class="sig-name descname"><span class="pre">__getstate__</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#object.__getstate__" title="Link to this definition">¶</a></dt>
<dd><p>Classes can further influence how their instances are pickled; if the class
defines the method <a class="reference internal" href="#object.__getstate__" title="object.__getstate__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getstate__()</span></code></a>, it is called and the return state is
pickled as the contents for the instance, instead of the contents of the
instance’s dictionary. If there is no <a class="reference internal" href="#object.__getstate__" title="object.__getstate__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getstate__()</span></code></a> method, the
instance’s <a class="reference external" href="https://docs.python.org/3/reference/datamodel.html#object.__dict__" title="(in Python v3.13)"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__dict__</span></code></a> is pickled.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="object.__setstate__">
<span class="sig-prename descclassname"><span class="pre">object.</span></span><span class="sig-name descname"><span class="pre">__setstate__</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">state</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#object.__setstate__" title="Link to this definition">¶</a></dt>
<dd><p>Upon unpickling, if the class also defines the method <a class="reference internal" href="#object.__setstate__" title="object.__setstate__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__setstate__()</span></code></a>,
it is called with the unpickled state. If there is no
<a class="reference internal" href="#object.__setstate__" title="object.__setstate__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__setstate__()</span></code></a> method, the pickled state must be a dictionary and its
items are assigned to the new instance’s dictionary. If a class defines both
<a class="reference internal" href="#object.__getstate__" title="object.__getstate__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getstate__()</span></code></a> and <a class="reference internal" href="#object.__setstate__" title="object.__setstate__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__setstate__()</span></code></a>, the state object needn’t be a
dictionary and these methods can do what they want.</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">object._jsonpickle_exclude</span> <span class="pre">=</span> <span class="pre">set()</span></span></dt>
<dd><p>Classes can specify attributes that they want to exclude from being pickled
by defining an attribute named <cite>_jsonpickle_exclude</cite>. This set should contain
the names of attributes of that class to exclude from being pickled.</p>
</dd></dl>
</section>
<section id="jsonpickle-handlers-custom-serialization-handlers">
<h3><a class="toc-backref" href="#id6" role="doc-backlink"><a class="reference internal" href="#module-jsonpickle.handlers" title="jsonpickle.handlers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">jsonpickle.handlers</span></code></a> – Custom Serialization Handlers</a><a class="headerlink" href="#jsonpickle-handlers-custom-serialization-handlers" title="Link to this heading">¶</a></h3>
<p>The <cite>jsonpickle.handlers</cite> module allows plugging in custom
serialization handlers at run-time. This feature is useful when
jsonpickle is unable to serialize objects that are not
under your direct control.</p>
<p id="module-jsonpickle.handlers">Custom handlers may be created to handle other objects. Each custom handler
must derive from <a class="reference internal" href="#jsonpickle.handlers.BaseHandler" title="jsonpickle.handlers.BaseHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">jsonpickle.handlers.BaseHandler</span></code></a> and
implement <code class="docutils literal notranslate"><span class="pre">flatten</span></code> and <code class="docutils literal notranslate"><span class="pre">restore</span></code>.</p>
<p>A handler can be bound to other types by calling
<a class="reference internal" href="#jsonpickle.handlers.register" title="jsonpickle.handlers.register"><code class="xref py py-func docutils literal notranslate"><span class="pre">jsonpickle.handlers.register()</span></code></a>.</p>
<dl class="py class">
<dt class="sig sig-object py" id="jsonpickle.handlers.ArrayHandler">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">jsonpickle.handlers.</span></span><span class="sig-name descname"><span class="pre">ArrayHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">context</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.ArrayHandler" title="Link to this definition">¶</a></dt>
<dd><p>Flatten and restore array.array objects</p>
<dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.ArrayHandler.flatten">
<span class="sig-name descname"><span class="pre">flatten</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">obj</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.ArrayHandler.flatten" title="Link to this definition">¶</a></dt>
<dd><p>Flatten <cite>obj</cite> into a json-friendly form and write result to <cite>data</cite>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>obj</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.13)"><em>object</em></a>) – The object to be serialized.</p></li>
<li><p><strong>data</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><em>dict</em></a>) – A partially filled dictionary which will contain the
json-friendly representation of <cite>obj</cite> once this method has
finished.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.ArrayHandler.restore">
<span class="sig-name descname"><span class="pre">restore</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.ArrayHandler.restore" title="Link to this definition">¶</a></dt>
<dd><p>Restore an object of the registered type from the json-friendly
representation <cite>obj</cite> and return it.</p>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="jsonpickle.handlers.BaseHandler">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">jsonpickle.handlers.</span></span><span class="sig-name descname"><span class="pre">BaseHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">context</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.BaseHandler" title="Link to this definition">¶</a></dt>
<dd><dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.BaseHandler.flatten">
<span class="sig-name descname"><span class="pre">flatten</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">obj</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.BaseHandler.flatten" title="Link to this definition">¶</a></dt>
<dd><p>Flatten <cite>obj</cite> into a json-friendly form and write result to <cite>data</cite>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>obj</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.13)"><em>object</em></a>) – The object to be serialized.</p></li>
<li><p><strong>data</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><em>dict</em></a>) – A partially filled dictionary which will contain the
json-friendly representation of <cite>obj</cite> once this method has
finished.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.BaseHandler.handles">
<em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">handles</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cls</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.BaseHandler.handles" title="Link to this definition">¶</a></dt>
<dd><p>Register this handler for the given class. Suitable as a decorator,
e.g.:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@MyCustomHandler</span><span class="o">.</span><span class="n">handles</span>
<span class="k">class</span> <span class="nc">MyCustomClass</span><span class="p">:</span>
<span class="k">def</span> <span class="nf">__reduce__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="o">...</span>
</pre></div>
</div>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.BaseHandler.restore">
<span class="sig-name descname"><span class="pre">restore</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">obj</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.BaseHandler.restore" title="Link to this definition">¶</a></dt>
<dd><p>Restore an object of the registered type from the json-friendly
representation <cite>obj</cite> and return it.</p>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="jsonpickle.handlers.CloneFactory">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">jsonpickle.handlers.</span></span><span class="sig-name descname"><span class="pre">CloneFactory</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">exemplar</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.CloneFactory" title="Link to this definition">¶</a></dt>
<dd><p>Serialization proxy for collections.defaultdict’s default_factory</p>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="jsonpickle.handlers.DatetimeHandler">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">jsonpickle.handlers.</span></span><span class="sig-name descname"><span class="pre">DatetimeHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">context</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.DatetimeHandler" title="Link to this definition">¶</a></dt>
<dd><p>Custom handler for datetime objects</p>
<p>Datetime objects use __reduce__, and they generate binary strings encoding
the payload. This handler encodes that payload to reconstruct the
object.</p>
<dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.DatetimeHandler.flatten">
<span class="sig-name descname"><span class="pre">flatten</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">obj</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.DatetimeHandler.flatten" title="Link to this definition">¶</a></dt>
<dd><p>Flatten <cite>obj</cite> into a json-friendly form and write result to <cite>data</cite>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>obj</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.13)"><em>object</em></a>) – The object to be serialized.</p></li>
<li><p><strong>data</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><em>dict</em></a>) – A partially filled dictionary which will contain the
json-friendly representation of <cite>obj</cite> once this method has
finished.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.DatetimeHandler.restore">
<span class="sig-name descname"><span class="pre">restore</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.DatetimeHandler.restore" title="Link to this definition">¶</a></dt>
<dd><p>Restore an object of the registered type from the json-friendly
representation <cite>obj</cite> and return it.</p>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="jsonpickle.handlers.LockHandler">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">jsonpickle.handlers.</span></span><span class="sig-name descname"><span class="pre">LockHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">context</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.LockHandler" title="Link to this definition">¶</a></dt>
<dd><p>Serialize threading.Lock objects</p>
<dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.LockHandler.flatten">
<span class="sig-name descname"><span class="pre">flatten</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">obj</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.LockHandler.flatten" title="Link to this definition">¶</a></dt>
<dd><p>Flatten <cite>obj</cite> into a json-friendly form and write result to <cite>data</cite>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>obj</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.13)"><em>object</em></a>) – The object to be serialized.</p></li>
<li><p><strong>data</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><em>dict</em></a>) – A partially filled dictionary which will contain the
json-friendly representation of <cite>obj</cite> once this method has
finished.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.LockHandler.restore">
<span class="sig-name descname"><span class="pre">restore</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.LockHandler.restore" title="Link to this definition">¶</a></dt>
<dd><p>Restore an object of the registered type from the json-friendly
representation <cite>obj</cite> and return it.</p>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="jsonpickle.handlers.QueueHandler">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">jsonpickle.handlers.</span></span><span class="sig-name descname"><span class="pre">QueueHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">context</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.QueueHandler" title="Link to this definition">¶</a></dt>
<dd><p>Opaquely serializes Queue objects</p>
<p>Queues contains mutex and condition variables which cannot be serialized.
Construct a new Queue instance when restoring.</p>
<dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.QueueHandler.flatten">
<span class="sig-name descname"><span class="pre">flatten</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">obj</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.QueueHandler.flatten" title="Link to this definition">¶</a></dt>
<dd><p>Flatten <cite>obj</cite> into a json-friendly form and write result to <cite>data</cite>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>obj</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.13)"><em>object</em></a>) – The object to be serialized.</p></li>
<li><p><strong>data</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><em>dict</em></a>) – A partially filled dictionary which will contain the
json-friendly representation of <cite>obj</cite> once this method has
finished.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.QueueHandler.restore">
<span class="sig-name descname"><span class="pre">restore</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.QueueHandler.restore" title="Link to this definition">¶</a></dt>
<dd><p>Restore an object of the registered type from the json-friendly
representation <cite>obj</cite> and return it.</p>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="jsonpickle.handlers.RegexHandler">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">jsonpickle.handlers.</span></span><span class="sig-name descname"><span class="pre">RegexHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">context</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.RegexHandler" title="Link to this definition">¶</a></dt>
<dd><p>Flatten _sre.SRE_Pattern (compiled regex) objects</p>
<dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.RegexHandler.flatten">
<span class="sig-name descname"><span class="pre">flatten</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">obj</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.RegexHandler.flatten" title="Link to this definition">¶</a></dt>
<dd><p>Flatten <cite>obj</cite> into a json-friendly form and write result to <cite>data</cite>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>obj</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.13)"><em>object</em></a>) – The object to be serialized.</p></li>
<li><p><strong>data</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><em>dict</em></a>) – A partially filled dictionary which will contain the
json-friendly representation of <cite>obj</cite> once this method has
finished.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.RegexHandler.restore">
<span class="sig-name descname"><span class="pre">restore</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.RegexHandler.restore" title="Link to this definition">¶</a></dt>
<dd><p>Restore an object of the registered type from the json-friendly
representation <cite>obj</cite> and return it.</p>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="jsonpickle.handlers.Registry">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">jsonpickle.handlers.</span></span><span class="sig-name descname"><span class="pre">Registry</span></span><a class="headerlink" href="#jsonpickle.handlers.Registry" title="Link to this definition">¶</a></dt>
<dd><dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.Registry.get">
<span class="sig-name descname"><span class="pre">get</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cls_or_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.Registry.get" title="Link to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>cls_or_name</strong> – the type or its fully qualified name</p></li>
<li><p><strong>default</strong> – default value, if a matching handler is not found</p></li>
</ul>
</dd>
</dl>
<p>Looks up a handler by type reference or its fully
qualified name. If a direct match
is not found, the search is performed over all
handlers registered with base=True.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.Registry.register">
<span class="sig-name descname"><span class="pre">register</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cls</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">handler</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">base</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.Registry.register" title="Link to this definition">¶</a></dt>
<dd><p>Register the a custom handler for a class</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>cls</strong> – The custom object class to handle</p></li>
<li><p><strong>handler</strong> – The custom handler class (if
None, a decorator wrapper is returned)</p></li>
<li><p><strong>base</strong> – Indicates whether the handler should
be registered for all subclasses</p></li>
</ul>
</dd>
</dl>
<p>This function can be also used as a decorator
by omitting the <cite>handler</cite> argument:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@jsonpickle</span><span class="o">.</span><span class="n">handlers</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">Foo</span><span class="p">,</span> <span class="n">base</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">FooHandler</span><span class="p">(</span><span class="n">jsonpickle</span><span class="o">.</span><span class="n">handlers</span><span class="o">.</span><span class="n">BaseHandler</span><span class="p">):</span>
<span class="k">pass</span>
</pre></div>
</div>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.Registry.unregister">
<span class="sig-name descname"><span class="pre">unregister</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cls</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.Registry.unregister" title="Link to this definition">¶</a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="jsonpickle.handlers.TextIOHandler">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">jsonpickle.handlers.</span></span><span class="sig-name descname"><span class="pre">TextIOHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">context</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.TextIOHandler" title="Link to this definition">¶</a></dt>
<dd><p>Serialize file descriptors as None because we cannot roundtrip</p>
<dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.TextIOHandler.flatten">
<span class="sig-name descname"><span class="pre">flatten</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">obj</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.TextIOHandler.flatten" title="Link to this definition">¶</a></dt>
<dd><p>Flatten <cite>obj</cite> into a json-friendly form and write result to <cite>data</cite>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>obj</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.13)"><em>object</em></a>) – The object to be serialized.</p></li>
<li><p><strong>data</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><em>dict</em></a>) – A partially filled dictionary which will contain the
json-friendly representation of <cite>obj</cite> once this method has
finished.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.TextIOHandler.restore">
<span class="sig-name descname"><span class="pre">restore</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.TextIOHandler.restore" title="Link to this definition">¶</a></dt>
<dd><p>Restore should never get called because flatten() returns None</p>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="jsonpickle.handlers.UUIDHandler">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">jsonpickle.handlers.</span></span><span class="sig-name descname"><span class="pre">UUIDHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">context</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.UUIDHandler" title="Link to this definition">¶</a></dt>
<dd><p>Serialize uuid.UUID objects</p>
<dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.UUIDHandler.flatten">
<span class="sig-name descname"><span class="pre">flatten</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">obj</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.UUIDHandler.flatten" title="Link to this definition">¶</a></dt>
<dd><p>Flatten <cite>obj</cite> into a json-friendly form and write result to <cite>data</cite>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>obj</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.13)"><em>object</em></a>) – The object to be serialized.</p></li>
<li><p><strong>data</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><em>dict</em></a>) – A partially filled dictionary which will contain the
json-friendly representation of <cite>obj</cite> once this method has
finished.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.handlers.UUIDHandler.restore">
<span class="sig-name descname"><span class="pre">restore</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.UUIDHandler.restore" title="Link to this definition">¶</a></dt>
<dd><p>Restore an object of the registered type from the json-friendly
representation <cite>obj</cite> and return it.</p>
</dd></dl>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="jsonpickle.handlers.get">
<span class="sig-prename descclassname"><span class="pre">jsonpickle.handlers.</span></span><span class="sig-name descname"><span class="pre">get</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.get" title="Link to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>cls_or_name</strong> – the type or its fully qualified name</p></li>
<li><p><strong>default</strong> – default value, if a matching handler is not found</p></li>
</ul>
</dd>
</dl>
<p>Looks up a handler by type reference or its fully
qualified name. If a direct match
is not found, the search is performed over all
handlers registered with base=True.</p>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="jsonpickle.handlers.register">
<span class="sig-prename descclassname"><span class="pre">jsonpickle.handlers.</span></span><span class="sig-name descname"><span class="pre">register</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">handler</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">base</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.register" title="Link to this definition">¶</a></dt>
<dd><p>Register the a custom handler for a class</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>cls</strong> – The custom object class to handle</p></li>
<li><p><strong>handler</strong> – The custom handler class (if
None, a decorator wrapper is returned)</p></li>
<li><p><strong>base</strong> – Indicates whether the handler should
be registered for all subclasses</p></li>
</ul>
</dd>
</dl>
<p>This function can be also used as a decorator
by omitting the <cite>handler</cite> argument:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@jsonpickle</span><span class="o">.</span><span class="n">handlers</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">Foo</span><span class="p">,</span> <span class="n">base</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">FooHandler</span><span class="p">(</span><span class="n">jsonpickle</span><span class="o">.</span><span class="n">handlers</span><span class="o">.</span><span class="n">BaseHandler</span><span class="p">):</span>
<span class="k">pass</span>
</pre></div>
</div>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="jsonpickle.handlers.unregister">
<span class="sig-prename descclassname"><span class="pre">jsonpickle.handlers.</span></span><span class="sig-name descname"><span class="pre">unregister</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cls</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.handlers.unregister" title="Link to this definition">¶</a></dt>
<dd></dd></dl>
</section>
</section>
<section id="low-level-api">
<h2><a class="toc-backref" href="#id7" role="doc-backlink">Low Level API</a><a class="headerlink" href="#low-level-api" title="Link to this heading">¶</a></h2>
<p>Typically this low level functionality is not needed by clients.</p>
<p>Note that arguments like <code class="docutils literal notranslate"><span class="pre">safe=True</span></code> do not make it safe to load an untrusted
jsonpickle string.</p>
<section id="module-jsonpickle.pickler">
<span id="jsonpickle-pickler-python-to-json-compatible-dict"></span><h3><a class="toc-backref" href="#id8" role="doc-backlink"><a class="reference internal" href="#module-jsonpickle.pickler" title="jsonpickle.pickler"><code class="xref py py-mod docutils literal notranslate"><span class="pre">jsonpickle.pickler</span></code></a> – Python to JSON-compatible dict</a><a class="headerlink" href="#module-jsonpickle.pickler" title="Link to this heading">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="jsonpickle.pickler.Pickler">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">jsonpickle.pickler.</span></span><span class="sig-name descname"><span class="pre">Pickler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">unpicklable</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">make_refs</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_depth</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">backend</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">keys</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">warn</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_iter</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">numeric_keys</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">use_decimal</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">use_base85</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fail_safe</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">include_properties</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">handle_readonly</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">original_object</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.pickler.Pickler" title="Link to this definition">¶</a></dt>
<dd><dl class="py method">
<dt class="sig sig-object py" id="jsonpickle.pickler.Pickler.flatten">
<span class="sig-name descname"><span class="pre">flatten</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">obj</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">reset</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#jsonpickle.pickler.Pickler.flatten" title="Link to this definition">¶</a></dt>
<dd><p>Takes an object and returns a JSON-safe representation of it.</p>
<p>Simply returns any of the basic builtin datatypes</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Pickler</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">flatten</span><span class="p">(</span><span class="s1">'hello world'</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'hello world'</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">flatten</span><span class="p">(</span><span class="mi">49</span><span class="p">)</span>
<span class="go">49</span>
<span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">flatten</span><span class="p">(</span><span class="mf">350.0</span><span class="p">)</span>
<span class="go">350.0</span>
<span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">flatten</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">flatten</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span>
<span class="go">False</span>