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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315
|
Help on module demjson3:
NAME
demjson3 - A JSON data encoder and decoder.
DESCRIPTION
This Python module implements the JSON (http://json.org/) data
encoding format; a subset of ECMAScript (aka JavaScript) for encoding
primitive data types (numbers, strings, booleans, lists, and
associative arrays) in a language-neutral simple text-based syntax.
It can encode or decode between JSON formatted strings and native
Python data types. Normally you would use the encode() and decode()
functions defined by this module, but if you want more control over
the processing you can use the JSON class.
This implementation tries to be as completely cormforming to all
intricacies of the standards as possible. It can operate in strict
mode (which only allows JSON-compliant syntax) or a non-strict mode
(which allows much more of the whole ECMAScript permitted syntax).
This includes complete support for Unicode strings (including
surrogate-pairs for non-BMP characters), and all number formats
including negative zero and IEEE 754 non-numbers such a NaN or
Infinity.
The JSON/ECMAScript to Python type mappings are:
---JSON--- ---Python---
null None
undefined undefined (note 1)
Boolean (true,false) bool (True or False)
Integer int or long (note 2)
Float float
String str or unicode ( "..." or u"..." )
Array [a, ...] list ( [...] )
Object {a:b, ...} dict ( {...} )
-- Note 1. an 'undefined' object is declared in this module which
represents the native Python value for this type when in
non-strict mode.
-- Note 2. some ECMAScript integers may be up-converted to Python
floats, such as 1e+40. Also integer -0 is converted to
float -0, so as to preserve the sign (which ECMAScript requires).
-- Note 3. numbers requiring more significant digits than can be
represented by the Python float type will be converted into a
Python Decimal type, from the standard 'decimal' module.
In addition, when operating in non-strict mode, several IEEE 754
non-numbers are also handled, and are mapped to specific Python
objects declared in this module:
NaN (not a number) nan (float('nan'))
Infinity, +Infinity inf (float('inf'))
-Infinity neginf (float('-inf'))
When encoding Python objects into JSON, you may use types other than
native lists or dictionaries, as long as they support the minimal
interfaces required of all sequences or mappings. This means you can
use generators and iterators, tuples, UserDict subclasses, etc.
To make it easier to produce JSON encoded representations of user
defined classes, if the object has a method named json_equivalent(),
then it will call that method and attempt to encode the object
returned from it instead. It will do this recursively as needed and
before any attempt to encode the object using it's default
strategies. Note that any json_equivalent() method should return
"equivalent" Python objects to be encoded, not an already-encoded
JSON-formatted string. There is no such aid provided to decode
JSON back into user-defined classes as that would dramatically
complicate the interface.
When decoding strings with this module it may operate in either
strict or non-strict mode. The strict mode only allows syntax which
is conforming to RFC 7159 (JSON), while the non-strict allows much
more of the permissible ECMAScript syntax.
The following are permitted when processing in NON-STRICT mode:
* Unicode format control characters are allowed anywhere in the input.
* All Unicode line terminator characters are recognized.
* All Unicode white space characters are recognized.
* The 'undefined' keyword is recognized.
* Hexadecimal number literals are recognized (e.g., 0xA6, 0177).
* String literals may use either single or double quote marks.
* Strings may contain \x (hexadecimal) escape sequences, as well as the
\v and \0 escape sequences.
* Lists may have omitted (elided) elements, e.g., [,,,,,], with
missing elements interpreted as 'undefined' values.
* Object properties (dictionary keys) can be of any of the
types: string literals, numbers, or identifiers (the later of
which are treated as if they are string literals)---as permitted
by ECMAScript. JSON only permits strings literals as keys.
Concerning non-strict and non-ECMAScript allowances:
* Octal numbers: If you allow the 'octal_numbers' behavior (which
is never enabled by default), then you can use octal integers
and octal character escape sequences (per the ECMAScript
standard Annex B.1.2). This behavior is allowed, if enabled,
because it was valid JavaScript at one time.
* Multi-line string literals: Strings which are more than one
line long (contain embedded raw newline characters) are never
permitted. This is neither valid JSON nor ECMAScript. Some other
JSON implementations may allow this, but this module considers
that behavior to be a mistake.
References:
* JSON (JavaScript Object Notation)
<http://json.org/>
* RFC 7159. The application/json Media Type for JavaScript Object Notation (JSON)
<http://www.ietf.org/rfc/rfc7159.txt>
* ECMA-262 3rd edition (1999)
<http://www.ecma-international.org/publications/files/ecma-st/ECMA-262.pdf>
* IEEE 754-1985: Standard for Binary Floating-Point Arithmetic.
<http://www.cs.berkeley.edu/~ejr/Projects/ieee754/>
CLASSES
builtins.Exception(builtins.BaseException)
JSONException
JSONAbort
JSONError
JSONDecodeError
JSONDecodeHookError
JSONEncodeError
JSONEncodeHookError
JSONSkipHook
JSONStopProcessing
builtins.int(builtins.object)
json_int
builtins.object
JSON
buffered_stream
decode_state
decode_statistics
encode_state
helpers
json_options
jsonlint
position_marker
codecs.CodecInfo(builtins.tuple)
utf32
class JSON(builtins.object)
| JSON(**kwargs)
|
| An encoder/decoder for JSON data streams.
|
| Usually you will call the encode() or decode() methods. The other
| methods are for lower-level processing.
|
| Whether the JSON parser runs in strict mode (which enforces exact
| compliance with the JSON spec) or the more forgiving non-string mode
| can be affected by setting the 'strict' argument in the object's
| initialization; or by assigning True or False to the 'strict'
| property of the object.
|
| You can also adjust a finer-grained control over strictness by
| allowing or forbidding specific behaviors. You can get a list of
| all the available behaviors by accessing the 'behaviors' property.
| Likewise the 'allowed_behaviors' and 'forbidden_behaviors' list which
| behaviors will be allowed and which will not. Call the allow()
| or forbid() methods to adjust these.
|
| Methods defined here:
|
| __init__(self, **kwargs)
| Creates a JSON encoder/decoder object.
|
| You may pass encoding and decoding options either by passing
| an argument named 'json_options' with an instance of a
| json_options class; or with individual keyword/values that will
| be used to initialize a new json_options object.
|
| You can also set hooks by using keyword arguments using the
| hook name; e.g., encode_dict=my_hook_func.
|
| call_hook(self, hook_name, input_object, position=None, *args, **kwargs)
| Wrapper function to invoke a user-supplied hook function.
|
| This will capture any exceptions raised by the hook and do something
| appropriate with it.
|
| clear_all_hooks(self)
| Unsets all hook callbacks, as previously set with set_hook().
|
| clear_hook(self, hookname)
| Unsets a hook callback, as previously set with set_hook().
|
| decode(self, txt, encoding=None, return_errors=False, return_stats=False)
| Decodes a JSON-encoded string into a Python object.
|
| The 'return_errors' parameter controls what happens if the
| input JSON has errors in it.
|
| * False: the first error will be raised as a Python
| exception. If there are no errors then the corresponding
| Python object will be returned.
|
| * True: the return value is always a 2-tuple: (object, error_list)
|
| decode_boolean(self, state)
| Intermediate-level decode for JSON boolean literals.
|
| Takes a string and a starting index, and returns a Python bool
| (True or False) and the index of the next unparsed character.
|
| decode_composite(self, state)
| Intermediate-level JSON decoder for composite literal types (array and object).
|
| decode_identifier(self, state, identifier_as_string=False)
| Decodes an identifier/keyword.
|
| decode_javascript_identifier(self, name)
| Convert a JavaScript identifier into a Python string object.
|
| This method can be overriden by a subclass to redefine how JavaScript
| identifiers are turned into Python objects. By default this just
| converts them into strings.
|
| decode_null(self, state)
| Intermediate-level decoder for ECMAScript 'null' keyword.
|
| Takes a string and a starting index, and returns a Python
| None object and the index of the next unparsed character.
|
| decode_number(self, state)
| Intermediate-level decoder for JSON numeric literals.
|
| Takes a string and a starting index, and returns a Python
| suitable numeric type and the index of the next unparsed character.
|
| The returned numeric type can be either of a Python int,
| long, or float. In addition some special non-numbers may
| also be returned such as nan, inf, and neginf (technically
| which are Python floats, but have no numeric value.)
|
| Ref. ECMAScript section 8.5.
|
| decode_string(self, state)
| Intermediate-level decoder for JSON string literals.
|
| Takes a string and a starting index, and returns a Python
| string (or unicode string) and the index of the next unparsed
| character.
|
| decodeobj(self, state, identifier_as_string=False, at_document_start=False)
| Intermediate-level JSON decoder.
|
| Takes a string and a starting index, and returns a two-tuple consting
| of a Python object and the index of the next unparsed character.
|
| If there is no value at all (empty string, etc), then None is
| returned instead of a tuple.
|
| encode(self, obj, encoding=None)
| Encodes the Python object into a JSON string representation.
|
| This method will first attempt to encode an object by seeing
| if it has a json_equivalent() method. If so than it will
| call that method and then recursively attempt to encode
| the object resulting from that call.
|
| Next it will attempt to determine if the object is a native
| type or acts like a squence or dictionary. If so it will
| encode that object directly.
|
| Finally, if no other strategy for encoding the object of that
| type exists, it will call the encode_default() method. That
| method currently raises an error, but it could be overridden
| by subclasses to provide a hook for extending the types which
| can be encoded.
|
| encode_boolean(self, bval, state)
| Encodes the Python boolean into a JSON Boolean literal.
|
| encode_composite(self, obj, state, obj_classification=None)
| Encodes just composite objects: dictionaries, lists, or sequences.
|
| Basically handles any python type for which iter() can create
| an iterator object.
|
| This method is not intended to be called directly. Use the
| encode() method instead.
|
| encode_date(self, dt, state)
|
| encode_datetime(self, dt, state)
|
| encode_enum(self, val, state)
| Encode a Python Enum value into JSON.
|
| encode_equivalent(self, obj, state)
| This method is used to encode user-defined class objects.
|
| The object being encoded should have a json_equivalent()
| method defined which returns another equivalent object which
| is easily JSON-encoded. If the object in question has no
| json_equivalent() method available then None is returned
| instead of a string so that the encoding will attempt the next
| strategy.
|
| If a caller wishes to disable the calling of json_equivalent()
| methods, then subclass this class and override this method
| to just return None.
|
| encode_null(self, state)
| Produces the JSON 'null' keyword.
|
| encode_number(self, n, state)
| Encodes a Python numeric type into a JSON numeric literal.
|
| The special non-numeric values of float('nan'), float('inf')
| and float('-inf') are translated into appropriate JSON
| literals.
|
| Note that Python complex types are not handled, as there is no
| ECMAScript equivalent type.
|
| encode_string(self, s, state)
| Encodes a Python string into a JSON string literal.
|
| encode_time(self, t, state)
|
| encode_timedelta(self, td, state)
|
| encode_undefined(self, state)
| Produces the ECMAScript 'undefined' keyword.
|
| has_hook(self, hook_name)
|
| islineterm(self, c)
| Determines if the given character is considered a line terminator.
|
| Ref. ECMAScript section 7.3
|
| isws(self, c)
| Determines if the given character is considered as white space.
|
| Note that Javscript is much more permissive on what it considers
| to be whitespace than does JSON.
|
| Ref. ECMAScript section 7.2
|
| recover_parser(self, state)
| Try to recover after a syntax error by locating the next "known" position.
|
| set_hook(self, hookname, function)
| Sets a user-defined callback function used during encoding or decoding.
|
| The 'hookname' argument must be a string containing the name of
| one of the available hooks, listed below.
|
| The 'function' argument must either be None, which disables the hook,
| or a callable function. Hooks do not stack, if you set a hook it will
| undo any previously set hook.
|
| Netsted values. When decoding JSON that has nested objects or
| arrays, the decoding hooks will be called once for every
| corresponding value, even if nested. Generally the decoding
| hooks will be called from the inner-most value outward, and
| then left to right.
|
| Skipping. Any hook function may raise a JSONSkipHook exception
| if it does not wish to handle the particular invocation. This
| will have the effect of skipping the hook for that particular
| value, as if the hook was net set.
|
| AVAILABLE HOOKS:
|
| * decode_string
| Called for every JSON string literal with the
| Python-equivalent string value as an argument. Expects to
| get a Python object in return.
|
| * decode_float:
| Called for every JSON number that looks like a float (has
| a "."). The string representation of the number is passed
| as an argument. Expects to get a Python object in return.
|
| * decode_number:
| Called for every JSON number. The string representation of
| the number is passed as an argument. Expects to get a
| Python object in return. NOTE: If the number looks like a
| float and the 'decode_float' hook is set, then this hook
| will not be called.
|
| * decode_array:
| Called for every JSON array. A Python list is passed as
| the argument, and expects to get a Python object back.
| NOTE: this hook will get called for every array, even
| for nested arrays.
|
| * decode_object:
| Called for every JSON object. A Python dictionary is passed
| as the argument, and expects to get a Python object back.
| NOTE: this hook will get called for every object, even
| for nested objects.
|
| * encode_value:
| Called for every Python object which is to be encoded into JSON.
|
| * encode_dict:
| Called for every Python dictionary or anything that looks
| like a dictionary.
|
| * encode_dict_key:
| Called for every dictionary key.
|
| * encode_sequence:
| Called for every Python sequence-like object that is not a
| dictionary or string. This includes lists and tuples.
|
| * encode_bytes:
| Called for every Python bytes or bytearray type; or for
| any memoryview with a byte ('B') item type. (Python 3 only)
|
| * encode_default:
| Called for any Python type which can not otherwise be converted
| into JSON, even after applying any other encoding hooks.
|
| skip_comment(self, state)
| Skips an ECMAScript comment, either // or /* style.
|
| The contents of the comment are returned as a string, as well
| as the index of the character immediately after the comment.
|
| skipws(self, state)
| Skips all whitespace, including comments and unicode whitespace
|
| Takes a string and a starting index, and returns the index of the
| next non-whitespace character.
|
| If the 'skip_comments' behavior is True and not running in
| strict JSON mode, then comments will be skipped over just like
| whitespace.
|
| skipws_nocomments(self, state)
| Skips whitespace (will not allow comments).
|
| try_encode_default(self, obj, state)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| options
| The optional behaviors used, e.g., the JSON conformance
| strictness. Returns an instance of json_options.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| all_hook_names = ('decode_number', 'decode_float', 'decode_object', 'd...
|
| json_syntax_characters = '{}[]"\\,:0123456789.-+abcdefghijklmnopqrstuv...
class JSONAbort(JSONException)
| Base class for all JSON-related exceptions.
|
| Method resolution order:
| JSONAbort
| JSONException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from JSONException:
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class JSONDecodeError(JSONError)
| JSONDecodeError(message, *args, **kwargs)
|
| An exception class raised when a JSON decoding error (syntax error) occurs.
|
| Method resolution order:
| JSONDecodeError
| JSONError
| JSONException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods inherited from JSONError:
|
| __init__(self, message, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| pretty_description(self, show_positions=True, filename=None)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from JSONError:
|
| position
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from JSONError:
|
| severities = frozenset({'error', 'fatal', 'info', 'warning'})
|
| ----------------------------------------------------------------------
| Data descriptors inherited from JSONException:
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class JSONDecodeHookError(JSONDecodeError)
| JSONDecodeHookError(hook_name, exc_info, encoded_obj, *args, **kwargs)
|
| An exception that occured within a decoder hook.
|
| The original exception is available in the 'hook_exception' attribute.
|
| Method resolution order:
| JSONDecodeHookError
| JSONDecodeError
| JSONError
| JSONException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods defined here:
|
| __init__(self, hook_name, exc_info, encoded_obj, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from JSONError:
|
| __repr__(self)
| Return repr(self).
|
| pretty_description(self, show_positions=True, filename=None)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from JSONError:
|
| position
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from JSONError:
|
| severities = frozenset({'error', 'fatal', 'info', 'warning'})
|
| ----------------------------------------------------------------------
| Data descriptors inherited from JSONException:
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class JSONEncodeError(JSONError)
| JSONEncodeError(message, *args, **kwargs)
|
| An exception class raised when a python object can not be encoded as a JSON string.
|
| Method resolution order:
| JSONEncodeError
| JSONError
| JSONException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods inherited from JSONError:
|
| __init__(self, message, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| pretty_description(self, show_positions=True, filename=None)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from JSONError:
|
| position
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from JSONError:
|
| severities = frozenset({'error', 'fatal', 'info', 'warning'})
|
| ----------------------------------------------------------------------
| Data descriptors inherited from JSONException:
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class JSONEncodeHookError(JSONEncodeError)
| JSONEncodeHookError(hook_name, exc_info, encoded_obj, *args, **kwargs)
|
| An exception that occured within an encoder hook.
|
| The original exception is available in the 'hook_exception' attribute.
|
| Method resolution order:
| JSONEncodeHookError
| JSONEncodeError
| JSONError
| JSONException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods defined here:
|
| __init__(self, hook_name, exc_info, encoded_obj, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from JSONError:
|
| __repr__(self)
| Return repr(self).
|
| pretty_description(self, show_positions=True, filename=None)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from JSONError:
|
| position
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from JSONError:
|
| severities = frozenset({'error', 'fatal', 'info', 'warning'})
|
| ----------------------------------------------------------------------
| Data descriptors inherited from JSONException:
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class JSONError(JSONException)
| JSONError(message, *args, **kwargs)
|
| Base class for all JSON-related errors.
|
| In addition to standard Python exceptions, these exceptions may
| also have additional properties:
|
| * severity - One of: 'fatal', 'error', 'warning', 'info'
| * position - An indication of the position in the input where the error occured.
| * outer_position - A secondary position (optional) that gives
| the location of the outer data item in which the error
| occured, such as the beginning of a string or an array.
| * context_description - A string that identifies the context
| in which the error occured. Default is "Context".
|
| Method resolution order:
| JSONError
| JSONException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods defined here:
|
| __init__(self, message, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| pretty_description(self, show_positions=True, filename=None)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| position
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| severities = frozenset({'error', 'fatal', 'info', 'warning'})
|
| ----------------------------------------------------------------------
| Data descriptors inherited from JSONException:
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class JSONException(builtins.Exception)
| Base class for all JSON-related exceptions.
|
| Method resolution order:
| JSONException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class JSONSkipHook(JSONException)
| An exception to be raised by user-defined code within hook
| callbacks to indicate the callback does not want to handle the
| situation.
|
| Method resolution order:
| JSONSkipHook
| JSONException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from JSONException:
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class JSONStopProcessing(JSONException)
| Can be raised by anyplace, including inside a hook function, to
| cause the entire encode or decode process to immediately stop
| with an error.
|
| Method resolution order:
| JSONStopProcessing
| JSONException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from JSONException:
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class buffered_stream(builtins.object)
| buffered_stream(txt='', encoding=None)
|
| A helper class for the JSON parser.
|
| It allows for reading an input document, while handling some
| low-level Unicode issues as well as tracking the current position
| in terms of line and column position.
|
| Methods defined here:
|
| __getitem__(self, index)
| Returns the character at the given index relative to the current position.
|
| If the index goes beyond the end of the input, or prior to the
| start when negative, then '' is returned.
|
| If the index provided is a slice object, then that range of
| characters is returned as a string. Note that a stride value other
| than 1 is not supported in the slice. To use a slice, do:
|
| s = my_stream[ 1:4 ]
|
| __init__(self, txt='', encoding=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| at_eol(self, allow_unicode_eol=True)
| Returns True if the current position contains an
| end-of-line control character.
|
| at_ws(self, allow_unicode_whitespace=True)
| Returns True if the current position contains a white-space
| character.
|
| clear_saved_position(self)
|
| peek(self, offset=0)
| Returns the character at the current position, or at a
| given offset away from the current position. If the position
| is beyond the limits of the document size, then an empty
| string '' is returned.
|
| peekstr(self, span=1, offset=0)
| Returns one or more characters starting at the current
| position, or at a given offset away from the current position,
| and continuing for the given span length. If the offset and
| span go outside the limit of the current document size, then
| the returned string may be shorter than the requested span
| length.
|
| pop(self)
| Returns the character at the current position and advances
| the position to the next character. At the end of the
| document this function returns an empty string.
|
| pop_identifier(self, match=None)
| Pops the sequence of characters at the current position
| that match the syntax for a JavaScript identifier.
|
| pop_if_startswith(self, s)
| Pops the sequence of characters if they match the given string.
|
| See also method: startswith()
|
| pop_while_in(self, chars)
| Pops a sequence of characters at the current position
| as long as each of them is in the given set of characters.
|
| popif(self, testfn)
| Just like the pop() function, but only returns the
| character if the given predicate test function succeeds.
|
| popstr(self, span=1, offset=0)
| Returns a string of one or more characters starting at the
| current position, and advances the position to the following
| character after the span. Will not go beyond the end of the
| document, so the returned string may be shorter than the
| requested span.
|
| popuntil(self, testfn, maxchars=None)
| Just like popwhile() method except the predicate function
| should return True to stop the sequence rather than False.
|
| See also methods: skipuntil() and popwhile()
|
| popwhile(self, testfn, maxchars=None)
| Pops all the characters starting at the current position as
| long as each character passes the given predicate function
| test. If maxchars a numeric value instead of None then then
| no more than that number of characters will be popped
| regardless of the predicate test.
|
| See also methods: skipwhile() and popuntil()
|
| reset(self)
| Clears the state to nothing.
|
| restore_position(self)
|
| rewind(self)
| Resets the position back to the start of the input text.
|
| save_position(self)
|
| set_text(self, txt, encoding=None)
| Changes the input text document and rewinds the position to
| the start of the new document.
|
| skip(self, span=1)
| Advances the current position by one (or the given number)
| of characters. Will not advance beyond the end of the
| document. Returns the number of characters skipped.
|
| skip_to_next_line(self, allow_unicode_eol=True)
| Advances the current position to the start of the next
| line. Will not advance beyond the end of the file. Note that
| the two-character sequence CR+LF is recognized as being just a
| single end-of-line marker.
|
| skipuntil(self, testfn)
| Advances the current position until a given predicate test
| function succeeds, or the end of the document is reached.
|
| Returns the actual number of characters skipped.
|
| The provided test function should take a single unicode
| character and return a boolean value, such as:
|
| lambda c : c == '.' # Skip to next period
|
| See also methods: skipwhile() and popuntil()
|
| skipwhile(self, testfn)
| Advances the current position until a given predicate test
| function fails, or the end of the document is reached.
|
| Returns the actual number of characters skipped.
|
| The provided test function should take a single unicode
| character and return a boolean value, such as:
|
| lambda c : c.isdigit() # Skip all digits
|
| See also methods: skipuntil() and popwhile()
|
| skipws(self, allow_unicode_whitespace=True)
| Advances the current position past all whitespace, or until
| the end of the document is reached.
|
| startswith(self, s)
| Determines if the text at the current position starts with
| the given string.
|
| See also method: pop_if_startswith()
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| at_end
| Returns True if the position is currently at the end of the
| document, of False otherwise.
|
| at_start
| Returns True if the position is currently at the start of
| the document, or False otherwise.
|
| bom
| The Unicode Byte-Order Mark (BOM), if any, that was present
| at the start of the input text. The returned BOM is a string
| of the raw bytes, and is not Unicode-decoded.
|
| codec
| The codec object used to perform Unicode decoding, or None.
|
| cpos
| The current character offset from the start of the document.
|
| position
| The current position (as a position_marker object).
| Returns a copy.
|
| text_context
| A short human-readable textual excerpt of the document at
| the current position, in English.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class decode_state(builtins.object)
| decode_state(options=None)
|
| An internal transient object used during JSON decoding to
| record the current parsing state and error messages.
|
| Methods defined here:
|
| __init__(self, options=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| push_cond(self, behavior_value, message, *args, **kwargs)
| Creates an conditional error or warning message.
|
| The behavior value (from json_options) controls whether
| a message will be pushed and whether it is an error
| or warning message.
|
| push_error(self, message, *args, **kwargs)
| Create an error.
|
| push_exception(self, exc)
| Add an already-built exception to the error list.
|
| push_fatal(self, message, *args, **kwargs)
| Create a fatal error.
|
| push_info(self, message, *args, **kwargs)
| Create a informational message.
|
| push_warning(self, message, *args, **kwargs)
| Create a warning.
|
| reset(self)
| Clears all errors, statistics, and input text.
|
| set_input(self, txt, encoding=None)
| Initialize the state by setting the input document text.
|
| update_depth_stats(self, **kwargs)
|
| update_float_stats(self, float_value, **kwargs)
|
| update_integer_stats(self, int_value, **kwargs)
|
| update_negzero_float_stats(self, **kwargs)
|
| update_negzero_int_stats(self, **kwargs)
|
| update_string_stats(self, s, **kwargs)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| has_errors
| Have any errors been seen already?
|
| has_fatal
| Have any errors been seen already?
|
| should_stop
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class decode_statistics(builtins.object)
| An object that records various statistics about a decoded JSON document.
|
| Methods defined here:
|
| __init__(self)
| Initialize self. See help(type(self)) for accurate signature.
|
| pretty_description(self, prefix='')
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| num_infinites
| Misspelled 'num_infinities' for backwards compatibility
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| double_int_max = 9007199254740991
|
| double_int_min = -9007199254740991
|
| int16_max = 32767
|
| int16_min = -32768
|
| int32_max = 2147483647
|
| int32_min = -2147483648
|
| int64_max = 9223372036854775807
|
| int64_min = -9223372036854775808
|
| int8_max = 127
|
| int8_min = -128
class encode_state(builtins.object)
| encode_state(jsopts=None, parent=None)
|
| An internal transient object used during JSON encoding to
| record the current construction state.
|
| Methods defined here:
|
| __eq__(self, other_state)
| Return self==value.
|
| __init__(self, jsopts=None, parent=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __lt__(self, other_state)
| Return self<value.
|
| append(self, s)
| Adds a string to the end of the current JSON document
|
| combine(self)
| Returns the accumulated string and resets the state to empty
|
| join_substate(self, other_state)
|
| make_substate(self)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
class helpers(builtins.object)
| A set of utility functions.
|
| Static methods defined here:
|
| auto_detect_encoding(s)
| Takes a string (or byte array) and tries to determine the Unicode encoding it is in.
|
| Returns the encoding name, as a string.
|
| char_is_identifier_leader(c)
| Determines if the character may be the first character of a
| JavaScript identifier.
|
| char_is_identifier_tail(c)
| Determines if the character may be part of a JavaScript
| identifier.
|
| char_is_json_eol(c)
| Determines if the given character is a JSON line separator
|
| char_is_json_ws(c)
| Determines if the given character is a JSON white-space character
|
| char_is_unicode_eol(c)
| Determines if the given character is a Unicode line or
| paragraph separator. These correspond to CR and LF as well as
| Unicode characters in the Zl or Zp categories.
|
| char_is_unicode_ws(c)
| Determines if the given character is a Unicode space character
|
| decode_binary(binarystring)
| Decodes a binary string into it's integer value.
|
| decode_hex(hexstring)
| Decodes a hexadecimal string into it's integer value.
|
| decode_octal(octalstring)
| Decodes an octal string into it's integer value.
|
| extend_and_flatten_list_with_sep(orig_seq, extension_seq, separator='')
|
| format_timedelta_iso(td)
| Encodes a datetime.timedelta into ISO-8601 Time Period format.
|
| is_binary_digit(c)
| Determines if the given character is a valid binary digit (0 or 1).
|
| is_hex_digit(c)
| Determines if the given character is a valid hexadecimal digit (0-9, a-f, A-F).
|
| is_infinite(n)
| Is the number infinite?
|
| is_nan(n)
| Is the number a NaN (not-a-number)?
|
| is_negzero(n)
| Is the number value a negative zero?
|
| is_octal_digit(c)
| Determines if the given character is a valid octal digit (0-7).
|
| isnumbertype(obj)
| Is the object of a Python number type (excluding complex)?
|
| isstringtype(obj)
| Is the object of a Python string type?
|
| lookup_codec(encoding)
| Wrapper around codecs.lookup().
|
| Returns None if codec not found, rather than raising a LookupError.
|
| make_raw_bytes(byte_list)
| Constructs a byte array (bytes in Python 3, str in Python 2) from a list of byte values (0-255).
|
| make_surrogate_pair(codepoint)
| Given a Unicode codepoint (int) returns a 2-tuple of surrogate codepoints.
|
| safe_unichr(codepoint)
| Just like Python's unichr() but works in narrow-Unicode Pythons.
|
| strip_format_control_chars(txt)
| Filters out all Unicode format control characters from the string.
|
| ECMAScript permits any Unicode "format control characters" to
| appear at any place in the source code. They are to be
| ignored as if they are not there before any other lexical
| tokenization occurs. Note that JSON does not allow them,
| except within string literals.
|
| * Ref. ECMAScript section 7.1.
| * http://en.wikipedia.org/wiki/Unicode_control_characters
|
| There are dozens of Format Control Characters, for example:
| U+00AD SOFT HYPHEN
| U+200B ZERO WIDTH SPACE
| U+2060 WORD JOINER
|
| surrogate_pair_as_unicode(c1, c2)
| Takes a pair of unicode surrogates and returns the equivalent unicode character.
|
| The input pair must be a surrogate pair, with c1 in the range
| U+D800 to U+DBFF and c2 in the range U+DC00 to U+DFFF.
|
| unicode_as_surrogate_pair(c)
| Takes a single unicode character and returns a sequence of surrogate pairs.
|
| The output of this function is a tuple consisting of one or two unicode
| characters, such that if the input character is outside the BMP range
| then the output is a two-character surrogate pair representing that character.
|
| If the input character is inside the BMP then the output tuple will have
| just a single character...the same one.
|
| unicode_decode(txt, encoding=None)
| Takes a string (or byte array) and tries to convert it to a Unicode string.
|
| Returns a named tuple: (string, codec, bom)
|
| The 'encoding' argument, if supplied, should either the name of
| a character encoding, or an instance of codecs.CodecInfo. If
| the encoding argument is None or "auto" then the encoding is
| automatically determined, if possible.
|
| Any BOM (Byte Order Mark) that is found at the beginning of the
| input will be stripped off and placed in the 'bom' portion of
| the returned value.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| always_use_custom_codecs = False
|
| hexdigits = '0123456789ABCDEFabcdef'
|
| javascript_reserved_words = frozenset({'break', 'case', 'catch', 'clas...
|
| maxunicode = 1114111
|
| octaldigits = '01234567'
|
| sys = <module 'sys' (built-in)>
|
| unsafe_string_chars = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0...
class json_int(builtins.int)
| json_int(*args, **kwargs)
|
| A subclass of the Python int/long that remembers its format (hex,octal,etc).
|
| Initialize it the same as an int, but also accepts an additional keyword
| argument 'number_format' which should be one of the NUMBER_FORMAT_* values.
|
| n = json_int( x[, base, number_format=NUMBER_FORMAT_DECIMAL] )
|
| Method resolution order:
| json_int
| builtins.int
| builtins.object
|
| Methods defined here:
|
| json_format(self)
| Returns the integer value formatted as a JSON literal
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, *args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| number_format
| The original radix format of the number
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.int:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return self&value.
|
| __bool__(self, /)
| self != 0
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(self, format_spec, /)
| Default object formatter.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __invert__(self, /)
| ~self
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __or__(self, value, /)
| Return self|value.
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rand__(self, value, /)
| Return value&self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __repr__(self, /)
| Return repr(self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rlshift__(self, value, /)
| Return value<<self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __ror__(self, value, /)
| Return value|self.
|
| __round__(...)
| Rounding an Integral returns itself.
| Rounding with an ndigits argument also returns an integer.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rrshift__(self, value, /)
| Return value>>self.
|
| __rshift__(self, value, /)
| Return self>>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(self, /)
| Returns size in memory, in bytes.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| __xor__(self, value, /)
| Return self^value.
|
| as_integer_ratio(self, /)
| Return integer ratio.
|
| Return a pair of integers, whose ratio is exactly equal to the original int
| and with a positive denominator.
|
| >>> (10).as_integer_ratio()
| (10, 1)
| >>> (-10).as_integer_ratio()
| (-10, 1)
| >>> (0).as_integer_ratio()
| (0, 1)
|
| bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| '0b100101'
| >>> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| to_bytes(self, /, length, byteorder, *, signed=False)
| Return an array of bytes representing an integer.
|
| length
| Length of bytes object to use. An OverflowError is raised if the
| integer is not representable with the given number of bytes.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value.
| signed
| Determines whether two's complement is used to represent the integer.
| If signed is False and a negative integer is given, an OverflowError
| is raised.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.int:
|
| from_bytes(bytes, byteorder, *, signed=False) from builtins.type
| Return the integer represented by the given array of bytes.
|
| bytes
| Holds the array of bytes to convert. The argument must either
| support the buffer protocol or be an iterable object producing bytes.
| Bytes and bytearray are examples of built-in objects that support the
| buffer protocol.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value.
| signed
| Indicates whether two's complement is used to represent the integer.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.int:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
class json_options(builtins.object)
| json_options(**kwargs)
|
| Options to determine how strict the decoder or encoder should be.
|
| Methods defined here:
|
| __eq__ = behaviors_eq(self, other)
| Determines if two options objects are equivalent.
|
| __init__(self, **kwargs)
| Set JSON encoding and decoding options.
|
| If 'strict' is set to True, then only strictly-conforming JSON
| output will be produced. Note that this means that some types
| of values may not be convertable and will result in a
| JSONEncodeError exception.
|
| If 'compactly' is set to True, then the resulting string will
| have all extraneous white space removed; if False then the
| string will be "pretty printed" with whitespace and indentation
| added to make it more readable.
|
| If 'escape_unicode' is set to True, then all non-ASCII characters
| will be represented as a unicode escape sequence; if False then
| the actual real unicode character will be inserted if possible.
|
| The 'escape_unicode' can also be a function, which when called
| with a single argument of a unicode character will return True
| if the character should be escaped or False if it should not.
|
| allow_all_numeric_signs(self, _name='all_numeric_signs', _value='allow')
| Set behavior all_numeric_signs to allow.
|
| allow_any_type_at_start(self, _name='any_type_at_start', _value='allow')
| Set behavior any_type_at_start to allow.
|
| allow_binary_numbers(self, _name='binary_numbers', _value='allow')
| Set behavior binary_numbers to allow.
|
| allow_bom(self, _name='bom', _value='allow')
| Set behavior bom to allow.
|
| allow_comments(self, _name='comments', _value='allow')
| Set behavior comments to allow.
|
| allow_control_char_in_string(self, _name='control_char_in_string', _value='allow')
| Set behavior control_char_in_string to allow.
|
| allow_duplicate_keys(self, _name='duplicate_keys', _value='allow')
| Set behavior duplicate_keys to allow.
|
| allow_extended_unicode_escapes(self, _name='extended_unicode_escapes', _value='allow')
| Set behavior extended_unicode_escapes to allow.
|
| allow_format_control_chars(self, _name='format_control_chars', _value='allow')
| Set behavior format_control_chars to allow.
|
| allow_hex_numbers(self, _name='hex_numbers', _value='allow')
| Set behavior hex_numbers to allow.
|
| allow_identifier_keys(self, _name='identifier_keys', _value='allow')
| Set behavior identifier_keys to allow.
|
| allow_initial_decimal_point(self, _name='initial_decimal_point', _value='allow')
| Set behavior initial_decimal_point to allow.
|
| allow_js_string_escapes(self, _name='js_string_escapes', _value='allow')
| Set behavior js_string_escapes to allow.
|
| allow_leading_zeros(self, _name='leading_zeros', _value='allow')
| Set behavior leading_zeros to allow.
|
| allow_non_numbers(self, _name='non_numbers', _value='allow')
| Set behavior non_numbers to allow.
|
| allow_non_portable(self, _name='non_portable', _value='allow')
| Set behavior non_portable to allow.
|
| allow_nonescape_characters(self, _name='nonescape_characters', _value='allow')
| Set behavior nonescape_characters to allow.
|
| allow_nonstring_keys(self, _name='nonstring_keys', _value='allow')
| Set behavior nonstring_keys to allow.
|
| allow_octal_numbers(self, _name='octal_numbers', _value='allow')
| Set behavior octal_numbers to allow.
|
| allow_omitted_array_elements(self, _name='omitted_array_elements', _value='allow')
| Set behavior omitted_array_elements to allow.
|
| allow_single_quoted_strings(self, _name='single_quoted_strings', _value='allow')
| Set behavior single_quoted_strings to allow.
|
| allow_trailing_comma(self, _name='trailing_comma', _value='allow')
| Set behavior trailing_comma to allow.
|
| allow_trailing_decimal_point(self, _name='trailing_decimal_point', _value='allow')
| Set behavior trailing_decimal_point to allow.
|
| allow_undefined_values(self, _name='undefined_values', _value='allow')
| Set behavior undefined_values to allow.
|
| allow_unicode_whitespace(self, _name='unicode_whitespace', _value='allow')
| Set behavior unicode_whitespace to allow.
|
| allow_zero_byte(self, _name='zero_byte', _value='allow')
| Set behavior zero_byte to allow.
|
| copy(self)
|
| copy_from(self, other)
|
| describe_behavior(self, name)
| Returns documentation about a given behavior.
|
| forbid_all_numeric_signs(self, _name='all_numeric_signs', _value='forbid')
| Set behavior all_numeric_signs to forbid.
|
| forbid_any_type_at_start(self, _name='any_type_at_start', _value='forbid')
| Set behavior any_type_at_start to forbid.
|
| forbid_binary_numbers(self, _name='binary_numbers', _value='forbid')
| Set behavior binary_numbers to forbid.
|
| forbid_bom(self, _name='bom', _value='forbid')
| Set behavior bom to forbid.
|
| forbid_comments(self, _name='comments', _value='forbid')
| Set behavior comments to forbid.
|
| forbid_control_char_in_string(self, _name='control_char_in_string', _value='forbid')
| Set behavior control_char_in_string to forbid.
|
| forbid_duplicate_keys(self, _name='duplicate_keys', _value='forbid')
| Set behavior duplicate_keys to forbid.
|
| forbid_extended_unicode_escapes(self, _name='extended_unicode_escapes', _value='forbid')
| Set behavior extended_unicode_escapes to forbid.
|
| forbid_format_control_chars(self, _name='format_control_chars', _value='forbid')
| Set behavior format_control_chars to forbid.
|
| forbid_hex_numbers(self, _name='hex_numbers', _value='forbid')
| Set behavior hex_numbers to forbid.
|
| forbid_identifier_keys(self, _name='identifier_keys', _value='forbid')
| Set behavior identifier_keys to forbid.
|
| forbid_initial_decimal_point(self, _name='initial_decimal_point', _value='forbid')
| Set behavior initial_decimal_point to forbid.
|
| forbid_js_string_escapes(self, _name='js_string_escapes', _value='forbid')
| Set behavior js_string_escapes to forbid.
|
| forbid_leading_zeros(self, _name='leading_zeros', _value='forbid')
| Set behavior leading_zeros to forbid.
|
| forbid_non_numbers(self, _name='non_numbers', _value='forbid')
| Set behavior non_numbers to forbid.
|
| forbid_non_portable(self, _name='non_portable', _value='forbid')
| Set behavior non_portable to forbid.
|
| forbid_nonescape_characters(self, _name='nonescape_characters', _value='forbid')
| Set behavior nonescape_characters to forbid.
|
| forbid_nonstring_keys(self, _name='nonstring_keys', _value='forbid')
| Set behavior nonstring_keys to forbid.
|
| forbid_octal_numbers(self, _name='octal_numbers', _value='forbid')
| Set behavior octal_numbers to forbid.
|
| forbid_omitted_array_elements(self, _name='omitted_array_elements', _value='forbid')
| Set behavior omitted_array_elements to forbid.
|
| forbid_single_quoted_strings(self, _name='single_quoted_strings', _value='forbid')
| Set behavior single_quoted_strings to forbid.
|
| forbid_trailing_comma(self, _name='trailing_comma', _value='forbid')
| Set behavior trailing_comma to forbid.
|
| forbid_trailing_decimal_point(self, _name='trailing_decimal_point', _value='forbid')
| Set behavior trailing_decimal_point to forbid.
|
| forbid_undefined_values(self, _name='undefined_values', _value='forbid')
| Set behavior undefined_values to forbid.
|
| forbid_unicode_whitespace(self, _name='unicode_whitespace', _value='forbid')
| Set behavior unicode_whitespace to forbid.
|
| forbid_zero_byte(self, _name='zero_byte', _value='forbid')
| Set behavior zero_byte to forbid.
|
| get_behavior(self, name)
| Returns the value for a given behavior
|
| indentation_for_level(self, level=0)
| Returns a whitespace string used for indenting.
|
| is_all(self, value)
| Determines if all the behaviors have the given value.
|
| make_decimal(self, s, sign='+')
| Converts a string into a decimal or float value.
|
| make_float(self, s, sign='+')
| Converts a string into a float or decimal value.
|
| make_int(self, s, sign=None, number_format='decimal')
| Makes an integer value according to the current options.
|
| First argument should be a string representation of the number,
| or an integer.
|
| Returns a number value, which could be an int, float, or decimal.
|
| reset_to_defaults(self)
|
| set_all(self, value)
| Changes all behaviors to have the given value.
|
| set_all_allow(self, _value='allow')
| Set all behaviors to value allow.
|
| set_all_forbid(self, _value='forbid')
| Set all behaviors to value forbid.
|
| set_all_warn(self, _value='warn')
| Set all behaviors to value warn.
|
| set_behavior(self, name, value)
| Changes the value for a given behavior
|
| set_indent(self, num_spaces, tab_width=0, limit=None)
| Changes the indentation properties when outputting JSON in non-compact mode.
|
| 'num_spaces' is the number of spaces to insert for each level
| of indentation, which defaults to 2.
|
| 'tab_width', if not 0, is the number of spaces which is equivalent
| to one tab character. Tabs will be output where possible rather
| than runs of spaces.
|
| 'limit', if not None, is the maximum indentation level after
| which no further indentation will be output.
|
| spaces_to_next_indent_level(self, min_spaces=1, subtract=0)
|
| suppress_warnings(self)
|
| warn_all_numeric_signs(self, _name='all_numeric_signs', _value='warn')
| Set behavior all_numeric_signs to warn.
|
| warn_any_type_at_start(self, _name='any_type_at_start', _value='warn')
| Set behavior any_type_at_start to warn.
|
| warn_binary_numbers(self, _name='binary_numbers', _value='warn')
| Set behavior binary_numbers to warn.
|
| warn_bom(self, _name='bom', _value='warn')
| Set behavior bom to warn.
|
| warn_comments(self, _name='comments', _value='warn')
| Set behavior comments to warn.
|
| warn_control_char_in_string(self, _name='control_char_in_string', _value='warn')
| Set behavior control_char_in_string to warn.
|
| warn_duplicate_keys(self, _name='duplicate_keys', _value='warn')
| Set behavior duplicate_keys to warn.
|
| warn_extended_unicode_escapes(self, _name='extended_unicode_escapes', _value='warn')
| Set behavior extended_unicode_escapes to warn.
|
| warn_format_control_chars(self, _name='format_control_chars', _value='warn')
| Set behavior format_control_chars to warn.
|
| warn_hex_numbers(self, _name='hex_numbers', _value='warn')
| Set behavior hex_numbers to warn.
|
| warn_identifier_keys(self, _name='identifier_keys', _value='warn')
| Set behavior identifier_keys to warn.
|
| warn_initial_decimal_point(self, _name='initial_decimal_point', _value='warn')
| Set behavior initial_decimal_point to warn.
|
| warn_js_string_escapes(self, _name='js_string_escapes', _value='warn')
| Set behavior js_string_escapes to warn.
|
| warn_leading_zeros(self, _name='leading_zeros', _value='warn')
| Set behavior leading_zeros to warn.
|
| warn_non_numbers(self, _name='non_numbers', _value='warn')
| Set behavior non_numbers to warn.
|
| warn_non_portable(self, _name='non_portable', _value='warn')
| Set behavior non_portable to warn.
|
| warn_nonescape_characters(self, _name='nonescape_characters', _value='warn')
| Set behavior nonescape_characters to warn.
|
| warn_nonstring_keys(self, _name='nonstring_keys', _value='warn')
| Set behavior nonstring_keys to warn.
|
| warn_octal_numbers(self, _name='octal_numbers', _value='warn')
| Set behavior octal_numbers to warn.
|
| warn_omitted_array_elements(self, _name='omitted_array_elements', _value='warn')
| Set behavior omitted_array_elements to warn.
|
| warn_single_quoted_strings(self, _name='single_quoted_strings', _value='warn')
| Set behavior single_quoted_strings to warn.
|
| warn_trailing_comma(self, _name='trailing_comma', _value='warn')
| Set behavior trailing_comma to warn.
|
| warn_trailing_decimal_point(self, _name='trailing_decimal_point', _value='warn')
| Set behavior trailing_decimal_point to warn.
|
| warn_undefined_values(self, _name='undefined_values', _value='warn')
| Set behavior undefined_values to warn.
|
| warn_unicode_whitespace(self, _name='unicode_whitespace', _value='warn')
| Set behavior unicode_whitespace to warn.
|
| warn_zero_byte(self, _name='zero_byte', _value='warn')
| Set behavior zero_byte to warn.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| all_behaviors
| Returns the names of all known behaviors.
|
| allow_behaviors
| Return the set of behaviors with the value allow.
|
| allow_or_warn_behaviors
| Returns the set of all behaviors that are not forbidden (i.e., are allowed or warned).
|
| forbid_behaviors
| Return the set of behaviors with the value forbid.
|
| inf
| The numeric value Infinity, either a float or a decimal.
|
| is_all_allow
| Determines if all the behaviors have the value allow.
|
| is_all_forbid
| Determines if all the behaviors have the value forbid.
|
| is_all_warn
| Determines if all the behaviors have the value warn.
|
| is_allow_all_numeric_signs
| Allow Numbers may be prefixed by any '+' and '-', e.g., +4, -+-+77
|
| is_allow_any_type_at_start
| Allow A JSON document may start with any type, not just arrays or objects
|
| is_allow_binary_numbers
| Allow Binary numbers, e.g., 0b1001
|
| is_allow_bom
| Allow A JSON document may start with a Unicode BOM (Byte Order Mark)
|
| is_allow_comments
| Allow JavaScript comments, both /*...*/ and //... styles
|
| is_allow_control_char_in_string
| Allow Strings may contain raw control characters without \u-escaping
|
| is_allow_duplicate_keys
| Allow Objects may have repeated keys
|
| is_allow_extended_unicode_escapes
| Allow Extended Unicode escape sequence \u{..} for non-BMP characters
|
| is_allow_format_control_chars
| Allow Unicode "format control characters" may appear in the input
|
| is_allow_hex_numbers
| Allow Hexadecimal numbers, e.g., 0x1f
|
| is_allow_identifier_keys
| Allow JavaScript identifiers are converted to strings when used as object keys
|
| is_allow_initial_decimal_point
| Allow Floating-point numbers may start with a decimal point (no units digit)
|
| is_allow_js_string_escapes
| Allow All JavaScript character \-escape sequences may be in strings
|
| is_allow_leading_zeros
| Allow Numbers may have leading zeros
|
| is_allow_non_numbers
| Allow Non-numbers may be used, such as NaN or Infinity
|
| is_allow_non_portable
| Allow Anything technically valid but likely to cause data portablibity issues
|
| is_allow_nonescape_characters
| Allow Unknown character \-escape sequences stand for that character (\Q -> 'Q')
|
| is_allow_nonstring_keys
| Allow Value types other than strings (or identifiers) may be used as object keys
|
| is_allow_octal_numbers
| Allow New-style octal numbers, e.g., 0o731 (see leading-zeros for legacy octals)
|
| is_allow_omitted_array_elements
| Allow Arrays may have omitted/elided elements, e.g., [1,,3] == [1,undefined,3]
|
| is_allow_single_quoted_strings
| Allow Strings may be delimited with both double (") and single (') quotation marks
|
| is_allow_trailing_comma
| Allow A final comma may end the list of array or object members
|
| is_allow_trailing_decimal_point
| Allow Floating-point number may end with a decimal point and no following fractional digits
|
| is_allow_undefined_values
| Allow The JavaScript 'undefined' value may be used
|
| is_allow_unicode_whitespace
| Allow Treat any Unicode whitespace character as valid whitespace
|
| is_allow_zero_byte
| Allow Strings may contain U+0000, which may not be safe for C-based programs
|
| is_forbid_all_numeric_signs
| Forbid Numbers may be prefixed by any '+' and '-', e.g., +4, -+-+77
|
| is_forbid_any_type_at_start
| Forbid A JSON document may start with any type, not just arrays or objects
|
| is_forbid_binary_numbers
| Forbid Binary numbers, e.g., 0b1001
|
| is_forbid_bom
| Forbid A JSON document may start with a Unicode BOM (Byte Order Mark)
|
| is_forbid_comments
| Forbid JavaScript comments, both /*...*/ and //... styles
|
| is_forbid_control_char_in_string
| Forbid Strings may contain raw control characters without \u-escaping
|
| is_forbid_duplicate_keys
| Forbid Objects may have repeated keys
|
| is_forbid_extended_unicode_escapes
| Forbid Extended Unicode escape sequence \u{..} for non-BMP characters
|
| is_forbid_format_control_chars
| Forbid Unicode "format control characters" may appear in the input
|
| is_forbid_hex_numbers
| Forbid Hexadecimal numbers, e.g., 0x1f
|
| is_forbid_identifier_keys
| Forbid JavaScript identifiers are converted to strings when used as object keys
|
| is_forbid_initial_decimal_point
| Forbid Floating-point numbers may start with a decimal point (no units digit)
|
| is_forbid_js_string_escapes
| Forbid All JavaScript character \-escape sequences may be in strings
|
| is_forbid_leading_zeros
| Forbid Numbers may have leading zeros
|
| is_forbid_non_numbers
| Forbid Non-numbers may be used, such as NaN or Infinity
|
| is_forbid_non_portable
| Forbid Anything technically valid but likely to cause data portablibity issues
|
| is_forbid_nonescape_characters
| Forbid Unknown character \-escape sequences stand for that character (\Q -> 'Q')
|
| is_forbid_nonstring_keys
| Forbid Value types other than strings (or identifiers) may be used as object keys
|
| is_forbid_octal_numbers
| Forbid New-style octal numbers, e.g., 0o731 (see leading-zeros for legacy octals)
|
| is_forbid_omitted_array_elements
| Forbid Arrays may have omitted/elided elements, e.g., [1,,3] == [1,undefined,3]
|
| is_forbid_single_quoted_strings
| Forbid Strings may be delimited with both double (") and single (') quotation marks
|
| is_forbid_trailing_comma
| Forbid A final comma may end the list of array or object members
|
| is_forbid_trailing_decimal_point
| Forbid Floating-point number may end with a decimal point and no following fractional digits
|
| is_forbid_undefined_values
| Forbid The JavaScript 'undefined' value may be used
|
| is_forbid_unicode_whitespace
| Forbid Treat any Unicode whitespace character as valid whitespace
|
| is_forbid_zero_byte
| Forbid Strings may contain U+0000, which may not be safe for C-based programs
|
| is_warn_all_numeric_signs
| Warn Numbers may be prefixed by any '+' and '-', e.g., +4, -+-+77
|
| is_warn_any_type_at_start
| Warn A JSON document may start with any type, not just arrays or objects
|
| is_warn_binary_numbers
| Warn Binary numbers, e.g., 0b1001
|
| is_warn_bom
| Warn A JSON document may start with a Unicode BOM (Byte Order Mark)
|
| is_warn_comments
| Warn JavaScript comments, both /*...*/ and //... styles
|
| is_warn_control_char_in_string
| Warn Strings may contain raw control characters without \u-escaping
|
| is_warn_duplicate_keys
| Warn Objects may have repeated keys
|
| is_warn_extended_unicode_escapes
| Warn Extended Unicode escape sequence \u{..} for non-BMP characters
|
| is_warn_format_control_chars
| Warn Unicode "format control characters" may appear in the input
|
| is_warn_hex_numbers
| Warn Hexadecimal numbers, e.g., 0x1f
|
| is_warn_identifier_keys
| Warn JavaScript identifiers are converted to strings when used as object keys
|
| is_warn_initial_decimal_point
| Warn Floating-point numbers may start with a decimal point (no units digit)
|
| is_warn_js_string_escapes
| Warn All JavaScript character \-escape sequences may be in strings
|
| is_warn_leading_zeros
| Warn Numbers may have leading zeros
|
| is_warn_non_numbers
| Warn Non-numbers may be used, such as NaN or Infinity
|
| is_warn_non_portable
| Warn Anything technically valid but likely to cause data portablibity issues
|
| is_warn_nonescape_characters
| Warn Unknown character \-escape sequences stand for that character (\Q -> 'Q')
|
| is_warn_nonstring_keys
| Warn Value types other than strings (or identifiers) may be used as object keys
|
| is_warn_octal_numbers
| Warn New-style octal numbers, e.g., 0o731 (see leading-zeros for legacy octals)
|
| is_warn_omitted_array_elements
| Warn Arrays may have omitted/elided elements, e.g., [1,,3] == [1,undefined,3]
|
| is_warn_single_quoted_strings
| Warn Strings may be delimited with both double (") and single (') quotation marks
|
| is_warn_trailing_comma
| Warn A final comma may end the list of array or object members
|
| is_warn_trailing_decimal_point
| Warn Floating-point number may end with a decimal point and no following fractional digits
|
| is_warn_undefined_values
| Warn The JavaScript 'undefined' value may be used
|
| is_warn_unicode_whitespace
| Warn Treat any Unicode whitespace character as valid whitespace
|
| is_warn_zero_byte
| Warn Strings may contain U+0000, which may not be safe for C-based programs
|
| leading_zero_radix_as_word
|
| nan
| The numeric value NaN, either a float or a decimal.
|
| neginf
| The numeric value -Infinity, either a float or a decimal.
|
| negzero_float
| The numeric value -0.0, either a float or a decimal.
|
| values
| Set of possible behavior values
|
| warn_behaviors
| Return the set of behaviors with the value warn.
|
| zero_float
| The numeric value 0.0, either a float or a decimal.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| all_numeric_signs
| Numbers may be prefixed by any '+' and '-', e.g., +4, -+-+77
|
| any_type_at_start
| A JSON document may start with any type, not just arrays or objects
|
| binary_numbers
| Binary numbers, e.g., 0b1001
|
| bom
| A JSON document may start with a Unicode BOM (Byte Order Mark)
|
| comments
| JavaScript comments, both /*...*/ and //... styles
|
| control_char_in_string
| Strings may contain raw control characters without \u-escaping
|
| duplicate_keys
| Objects may have repeated keys
|
| encode_enum_as
| The strategy for encoding Python Enum values.
|
| extended_unicode_escapes
| Extended Unicode escape sequence \u{..} for non-BMP characters
|
| format_control_chars
| Unicode "format control characters" may appear in the input
|
| hex_numbers
| Hexadecimal numbers, e.g., 0x1f
|
| identifier_keys
| JavaScript identifiers are converted to strings when used as object keys
|
| initial_decimal_point
| Floating-point numbers may start with a decimal point (no units digit)
|
| js_string_escapes
| All JavaScript character \-escape sequences may be in strings
|
| leading_zero_radix
| The radix to be used for numbers with leading zeros. 8 or 10
|
| leading_zeros
| Numbers may have leading zeros
|
| non_numbers
| Non-numbers may be used, such as NaN or Infinity
|
| non_portable
| Anything technically valid but likely to cause data portablibity issues
|
| nonescape_characters
| Unknown character \-escape sequences stand for that character (\Q -> 'Q')
|
| nonstring_keys
| Value types other than strings (or identifiers) may be used as object keys
|
| octal_numbers
| New-style octal numbers, e.g., 0o731 (see leading-zeros for legacy octals)
|
| omitted_array_elements
| Arrays may have omitted/elided elements, e.g., [1,,3] == [1,undefined,3]
|
| single_quoted_strings
| Strings may be delimited with both double (") and single (') quotation marks
|
| sort_keys
| The method used to sort dictionary keys when encoding JSON
|
| strictness
|
| trailing_comma
| A final comma may end the list of array or object members
|
| trailing_decimal_point
| Floating-point number may end with a decimal point and no following fractional digits
|
| undefined_values
| The JavaScript 'undefined' value may be used
|
| unicode_whitespace
| Treat any Unicode whitespace character as valid whitespace
|
| zero_byte
| Strings may contain U+0000, which may not be safe for C-based programs
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
class jsonlint(builtins.object)
| jsonlint(program_name='jsonlint', stdin=None, stdout=None, stderr=None)
|
| This class contains most of the logic for the "jsonlint" command.
|
| You generally create an instance of this class, to defined the
| program's environment, and then call the main() method. A simple
| wrapper to turn this into a script might be:
|
| import sys, demjson
| if __name__ == '__main__':
| lint = demjson.jsonlint( sys.argv[0] )
| return lint.main( sys.argv[1:] )
|
| Methods defined here:
|
| __init__(self, program_name='jsonlint', stdin=None, stdout=None, stderr=None)
| Create an instance of a "jsonlint" program.
|
| You can optionally pass options to define the program's environment:
|
| * program_name - the name of the program, usually sys.argv[0]
| * stdin - the file object to use for input, default sys.stdin
| * stdout - the file object to use for outut, default sys.stdout
| * stderr - the file object to use for error output, default sys.stderr
|
| After creating an instance, you typically call the main() method.
|
| main(self, argv)
| The main routine for program "jsonlint".
|
| Should be called with sys.argv[1:] as its sole argument.
|
| Note sys.argv[0] which normally contains the program name
| should not be passed to main(); instead this class itself
| is initialized with sys.argv[0].
|
| Use "--help" for usage syntax, or consult the 'usage' member.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| usage
| A multi-line string containing the program usage instructions.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| SUCCESS_FAIL = 'E'
|
| SUCCESS_OK = 'OK'
|
| SUCCESS_WARNING = 'W'
class position_marker(builtins.object)
| position_marker(offset=0, line=1, column=0, text_after=None)
|
| A position marks a specific place in a text document.
| It consists of the following attributes:
|
| * line - The line number, starting at 1
| * column - The column on the line, starting at 0
| * char_position - The number of characters from the start of
| the document, starting at 0
| * text_after - (optional) a short excerpt of the text of
| document starting at the current position
|
| Lines are separated by any Unicode line separator character. As an
| exception a CR+LF character pair is treated as being a single line
| separator demarcation.
|
| Columns are simply a measure of the number of characters after the
| start of a new line, starting at 0. Visual effects caused by
| Unicode characters such as combining characters, bidirectional
| text, zero-width characters and so on do not affect the
| computation of the column regardless of visual appearance.
|
| The char_position is a count of the number of characters since the
| beginning of the document, starting at 0. As used within the
| buffered_stream class, if the document starts with a Unicode Byte
| Order Mark (BOM), the BOM prefix is NOT INCLUDED in the count.
|
| Methods defined here:
|
| __init__(self, offset=0, line=1, column=0, text_after=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| __str__(self)
| Same as the describe() function.
|
| advance(self, s)
| Advance the position from its current place according to
| the given string of characters.
|
| copy(self)
| Create a copy of the position object.
|
| describe(self, show_text=True)
| Returns a human-readable description of the position, in English.
|
| rewind(self)
| Set the position to the start of the document.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| at_start
| Returns True if the position is at the start of the document.
|
| char_position
| The current character offset from the beginning of the
| document, starts at 0.
|
| column
| The current character column from the beginning of the
| document, starts at 0.
|
| line
| The current line within the document, starts at 1.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| at_end
| Returns True if the position is at the end of the document.
|
| This property must be set by the user.
|
| text_after
| Returns a textual excerpt starting at the current position.
|
| This property must be set by the user.
class utf32(codecs.CodecInfo)
| utf32(encode, decode, streamreader=None, streamwriter=None, incrementalencoder=None, incrementaldecoder=None, name=None, *, _is_text_encoding=None)
|
| Unicode UTF-32 and UCS4 encoding/decoding support.
|
| This is for older Pythons whch did not have UTF-32 codecs.
|
| JSON requires that all JSON implementations must support the
| UTF-32 encoding (as well as UTF-8 and UTF-16). But earlier
| versions of Python did not provide a UTF-32 codec, so we must
| implement UTF-32 ourselves in case we need it.
|
| See http://en.wikipedia.org/wiki/UTF-32
|
| Method resolution order:
| utf32
| codecs.CodecInfo
| builtins.tuple
| builtins.object
|
| Static methods defined here:
|
| decode(obj, errors='strict', endianness=None)
| Decodes a UTF-32 byte string into a Unicode string.
|
| Returns tuple (bytearray, num_bytes)
|
| The errors argument shold be one of 'strict', 'ignore',
| 'replace', 'backslashreplace', or 'xmlcharrefreplace'.
|
| The endianness should either be None (for auto-guessing), or a
| word that starts with 'B' (big) or 'L' (little).
|
| Will detect a Byte-Order Mark. If a BOM is found and endianness
| is also set, then the two must match.
|
| If neither a BOM is found nor endianness is set, then big
| endian order is assumed.
|
| encode(obj, errors='strict', endianness=None, include_bom=True)
| Encodes a Unicode string into a UTF-32 encoded byte string.
|
| Returns a tuple: (bytearray, num_chars)
|
| The errors argument should be one of 'strict', 'ignore', or 'replace'.
|
| The endianness should be one of:
| * 'B', '>', or 'big' -- Big endian
| * 'L', '<', or 'little' -- Little endien
| * None -- Default, from sys.byteorder
|
| If include_bom is true a Byte-Order Mark will be written to
| the beginning of the string, otherwise it will be omitted.
|
| lookup(name)
| A standard Python codec lookup function for UCS4/UTF32.
|
| If if recognizes an encoding name it returns a CodecInfo
| structure which contains the various encode and decoder
| functions to use.
|
| utf32be_decode(obj, errors='strict')
| Decodes a UTF-32BE (big endian) byte string into a Unicode string.
|
| utf32be_encode(obj, errors='strict', include_bom=False)
| Encodes a Unicode string into a UTF-32BE (big endian) encoded byte string.
|
| utf32le_decode(obj, errors='strict')
| Decodes a UTF-32LE (little endian) byte string into a Unicode string.
|
| utf32le_encode(obj, errors='strict', include_bom=False)
| Encodes a Unicode string into a UTF-32LE (little endian) encoded byte string.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| BOM_UTF32_BE = b'\x00\x00\xfe\xff'
|
| BOM_UTF32_LE = b'\xff\xfe\x00\x00'
|
| ----------------------------------------------------------------------
| Methods inherited from codecs.CodecInfo:
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from codecs.CodecInfo:
|
| __new__(cls, encode, decode, streamreader=None, streamwriter=None, incrementalencoder=None, incrementaldecoder=None, name=None, *, _is_text_encoding=None)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from codecs.CodecInfo:
|
| __dict__
| dictionary for instance variables (if defined)
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return key in self.
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
FUNCTIONS
decode(txt, encoding=None, **kwargs)
Decodes a JSON-encoded string into a Python object.
== Optional arguments ==
* 'encoding' (string, default None)
This argument provides a hint regarding the character encoding
that the input text is assumed to be in (if it is not already a
unicode string type).
If set to None then autodetection of the encoding is attempted
(see discussion above). Otherwise this argument should be the
name of a registered codec (see the standard 'codecs' module).
* 'strict' (Boolean, default False)
If 'strict' is set to True, then those strings that are not
entirely strictly conforming to JSON will result in a
JSONDecodeError exception.
* 'return_errors' (Boolean, default False)
Controls the return value from this function. If False, then
only the Python equivalent object is returned on success, or
an error will be raised as an exception.
If True then a 2-tuple is returned: (object, error_list). The
error_list will be an empty list [] if the decoding was
successful, otherwise it will be a list of all the errors
encountered. Note that it is possible for an object to be
returned even if errors were encountered.
* 'return_stats' (Boolean, default False)
Controls whether statistics about the decoded JSON document
are returns (and instance of decode_statistics).
If True, then the stats object will be added to the end of the
tuple returned. If return_errors is also set then a 3-tuple
is returned, otherwise a 2-tuple is returned.
* 'write_errors' (Boolean OR File-like object, default False)
Controls what to do with errors.
- If False, then the first decoding error is raised as an exception.
- If True, then errors will be printed out to sys.stderr.
- If a File-like object, then errors will be printed to that file.
The write_errors and return_errors arguments can be set
independently.
* 'filename_for_errors' (string or None)
Provides a filename to be used when writting error messages.
* 'allow_xxx', 'warn_xxx', and 'forbid_xxx' (Booleans)
These arguments allow for fine-adjustments to be made to the
'strict' argument, by allowing or forbidding specific
syntaxes.
There are many of these arguments, named by replacing the
"xxx" with any number of possible behavior names (See the JSON
class for more details).
Each of these will allow (or forbid) the specific behavior,
after the evaluation of the 'strict' argument. For example,
if strict=True then by also passing 'allow_comments=True' then
comments will be allowed. If strict=False then
forbid_comments=True will allow everything except comments.
Unicode decoding:
-----------------
The input string can be either a python string or a python unicode
string (or a byte array in Python 3). If it is already a unicode
string, then it is assumed that no character set decoding is
required.
However, if you pass in a non-Unicode text string (a Python 2
'str' type or a Python 3 'bytes' or 'bytearray') then an attempt
will be made to auto-detect and decode the character encoding.
This will be successful if the input was encoded in any of UTF-8,
UTF-16 (BE or LE), or UTF-32 (BE or LE), and of course plain ASCII
works too.
Note though that if you know the character encoding, then you
should convert to a unicode string yourself, or pass it the name
of the 'encoding' to avoid the guessing made by the auto
detection, as with
python_object = demjson.decode( input_bytes, encoding='utf8' )
Callback hooks:
---------------
You may supply callback hooks by using the hook name as the
named argument, such as:
decode_float=decimal.Decimal
See the hooks documentation on the JSON.set_hook() method.
decode_file(filename, encoding=None, **kwargs)
Decodes JSON found in the given file.
See the decode() function for a description of other possible options.
determine_float_limits(number_type=<class 'float'>)
Determines the precision and range of the given float type.
The passed in 'number_type' argument should refer to the type of
floating-point number. It should either be the built-in 'float',
or decimal context or constructor; i.e., one of:
# 1. FLOAT TYPE
determine_float_limits( float )
# 2. DEFAULT DECIMAL CONTEXT
determine_float_limits( decimal.Decimal )
# 3. CUSTOM DECIMAL CONTEXT
ctx = decimal.Context( prec=75 )
determine_float_limits( ctx )
Returns a named tuple with components:
( significant_digits,
max_exponent,
min_exponent )
Where:
* significant_digits -- maximum number of *decimal* digits
that can be represented without any loss of precision.
This is conservative, so if there are 16 1/2 digits, it
will return 16, not 17.
* max_exponent -- The maximum exponent (power of 10) that can
be represented before an overflow (or rounding to
infinity) occurs.
* min_exponent -- The minimum exponent (negative power of 10)
that can be represented before either an underflow
(rounding to zero) or a subnormal result (loss of
precision) occurs. Note this is conservative, as
subnormal numbers are excluded.
determine_float_precision()
# For backwards compatibility with older demjson versions:
encode(obj, encoding=None, **kwargs)
Encodes a Python object into a JSON-encoded string.
* 'strict' (Boolean, default False)
If 'strict' is set to True, then only strictly-conforming JSON
output will be produced. Note that this means that some types
of values may not be convertable and will result in a
JSONEncodeError exception.
* 'compactly' (Boolean, default True)
If 'compactly' is set to True, then the resulting string will
have all extraneous white space removed; if False then the
string will be "pretty printed" with whitespace and
indentation added to make it more readable.
* 'encode_namedtuple_as_object' (Boolean or callable, default True)
If True, then objects of type namedtuple, or subclasses of
'tuple' that have an _asdict() method, will be encoded as an
object rather than an array.
If can also be a predicate function that takes a namedtuple
object as an argument and returns True or False.
* 'indent_amount' (Integer, default 2)
The number of spaces to output for each indentation level.
If 'compactly' is True then indentation is ignored.
* 'indent_limit' (Integer or None, default None)
If not None, then this is the maximum limit of indentation
levels, after which further indentation spaces are not
inserted. If None, then there is no limit.
CONCERNING CHARACTER ENCODING:
The 'encoding' argument should be one of:
* None - The return will be a Unicode string.
* encoding_name - A string which is the name of a known
encoding, such as 'UTF-8' or 'ascii'.
* codec - A CodecInfo object, such as as found by codecs.lookup().
This allows you to use a custom codec as well as those
built into Python.
If an encoding is given (either by name or by codec), then the
returned value will be a byte array (Python 3), or a 'str' string
(Python 2); which represents the raw set of bytes. Otherwise,
if encoding is None, then the returned value will be a Unicode
string.
The 'escape_unicode' argument is used to determine which characters
in string literals must be \u escaped. Should be one of:
* True -- All non-ASCII characters are always \u escaped.
* False -- Try to insert actual Unicode characters if possible.
* function -- A user-supplied function that accepts a single
unicode character and returns True or False; where True
means to \u escape that character.
Regardless of escape_unicode, certain characters will always be
\u escaped. Additionaly any characters not in the output encoding
repertoire for the encoding codec will be \u escaped as well.
encode_to_file(filename, obj, encoding='utf-8', overwrite=False, **kwargs)
Encodes a Python object into JSON and writes into the given file.
If no encoding is given, then UTF-8 will be used.
See the encode() function for a description of other possible options.
If the file already exists and the 'overwrite' option is not set
to True, then the existing file will not be overwritten. (Note,
there is a subtle race condition in the check so there are
possible conditions in which a file may be overwritten)
extend_and_flatten_list_with_sep(orig_seq, extension_seq, separator='')
extend_list_with_sep(orig_seq, extension_seq, sepchar='')
skipstringsafe(s, start=0, end=None)
skipstringsafe_slow(s, start=0, end=None)
smart_sort_transform(key)
DATA
ALLOW = 'allow'
FORBID = 'forbid'
NUMBER_AUTO = 'auto'
NUMBER_DECIMAL = 'decimal'
NUMBER_FLOAT = 'float'
NUMBER_FORMAT_BINARY = 'binary'
NUMBER_FORMAT_DECIMAL = 'decimal'
NUMBER_FORMAT_HEX = 'hex'
NUMBER_FORMAT_LEGACYOCTAL = 'legacyoctal'
NUMBER_FORMAT_OCTAL = 'octal'
SORT_ALPHA = 'alpha'
SORT_ALPHA_CI = 'alpha_ci'
SORT_NONE = 'none'
SORT_PRESERVE = 'preserve'
SORT_SMART = 'smart'
STRICTNESS_STRICT = 'strict'
STRICTNESS_TOLERANT = 'tolerant'
STRICTNESS_WARN = 'warn'
WARN = 'warn'
__homepage__ = 'http://nielstron.github.io/demjson3/'
__version_info__ = version_info(major=3, minor=0, micro=4)
content_type = 'application/json'
file_ext = 'json'
float_maxexp = 308
float_minexp = -308
float_sigdigits = 16
inf = inf
nan = nan
neginf = -inf
sorting_method_aliases = {'ci': 'alpha_ci'}
sorting_methods = {'alpha': 'Sort strictly alphabetically', 'alpha_ci'...
syntax_error = demjson3.undefined
undefined = demjson3.undefined
version = '3.0.4'
version_info = version_info(major=3, minor=0, micro=4)
vi = sys.version_info(major=3, minor=8, micro=10, releaselevel='final'...
VERSION
3.0.4
DATE
2021-09-08
AUTHOR
Deron Meranda <http://deron.meranda.us/>, Niels Mündler
CREDITS
Copyright (c) 2006-2021 Deron E. Meranda <http://deron.meranda.us/>, Niels Mündler
Licensed under GNU LGPL (GNU Lesser General Public License) version 3.0
or later. See LICENSE.txt included with this software.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
or <http://www.fsf.org/licensing/>.
FILE
demjson3.py
|