XML to JSON Sergey Svistunov

Convert 1,000,000 person records from XML to JSON as fast as possible.

Input

XML document on STDIN:

<?xml version="1.0" encoding="UTF-8"?>
<persons>
    <person id="1512376">
        <age>30</age>
        <height>169.1</height>
        <married>true</married>
        <phone code="+6"><number>1283603279</number></phone>
        <phone code="+6"><number>1659964668</number></phone>
    </person>
    ...
</persons>

Output

One JSON object per person to STDOUT, preserving order:

{
    "id": 1512376,
    "age": 30,
    "height": 169.1,
    "married": true,
    "phones": [
        {
            "code": "+6",
            "number": 1283603279
        },
        {
            "code": "+6",
            "number": 1659964668
        }
    ]
}

Constraints

  • Preserve the order of persons
  • Omit the phones field if the phone array is empty
  • Maximum number of phones per person is 3
Back to listJul 27, 2024 11:06Joad NacerJoad NacerScore: 3,554Success
Source Code

Source code access is restricted. Log in to request access.

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 27, 2024 11:053,36655,911,97022,463,0008,168,00093,085,696
2Jul 27, 2024 11:053,38056,476,04621,831,0008,931,00093,036,544
3Jul 27, 2024 11:063,38757,116,70922,866,0007,953,00092,848,128
4Jul 27, 2024 11:053,39756,819,06220,941,0009,972,00093,036,544
5Jul 27, 2024 11:063,40459,547,09919,987,00010,993,00093,093,888
6Jul 27, 2024 11:053,43352,788,01321,160,00010,076,00092,876,800
7Jul 27, 2024 11:053,43548,950,48622,186,0009,076,00093,167,616
8Jul 27, 2024 11:063,45253,423,23622,296,0009,121,00093,155,328
9Jul 27, 2024 11:063,45459,713,11822,308,0009,126,00093,044,736
10Jul 27, 2024 11:063,46663,516,25422,382,0009,156,00092,901,376
11Jul 27, 2024 11:063,46756,037,70022,390,0009,159,00093,171,712
12Jul 27, 2024 11:063,47259,216,46021,405,00010,192,00093,065,216
13Jul 27, 2024 11:063,47561,564,30521,739,0009,881,00093,032,448
14Jul 27, 2024 11:063,48054,235,72921,769,0009,895,00092,942,336
15Jul 27, 2024 11:053,49154,296,89520,845,00010,919,00093,179,904
16Jul 27, 2024 11:063,53892,086,01132,197,477094,498,816
17Jul 27, 2024 11:063,54792,243,37032,273,491094,507,008
18Jul 27, 2024 11:053,552106,174,82532,323,789094,507,008
19Jul 27, 2024 11:053,554100,926,97632,337,168094,494,720
20Jul 27, 2024 11:053,55596,083,62532,352,049094,502,912
21Jul 27, 2024 11:063,555110,870,18832,352,933094,633,984
22Jul 27, 2024 11:063,55798,794,47432,367,425094,507,008
23Jul 27, 2024 11:063,57992,993,41832,571,067094,490,624
24Jul 27, 2024 11:063,58195,560,99732,584,540094,625,792
25Jul 27, 2024 11:054,50874,579,39422,011,00019,010,00092,983,296
26Jul 27, 2024 11:064,54866,574,93022,209,00019,181,00093,102,080
27Jul 27, 2024 11:064,74973,138,05423,115,00020,100,00093,073,408
28Jul 27, 2024 11:065,37378,876,26021,951,00026,940,00093,085,696
29Jul 27, 2024 11:065,92176,742,46923,947,00029,933,00093,290,496
30Jul 27, 2024 11:066,10984,926,48323,246,00032,343,00093,196,288
31Jul 27, 2024 11:067,23594,034,66824,937,00040,897,00093,134,848
32Jul 27, 2024 11:057,31093,053,98625,198,00041,325,00093,224,960
33Jul 27, 2024 11:067,32290,166,54525,237,00041,389,00093,167,616
34Jul 27, 2024 11:057,36495,065,31424,004,00043,008,00093,274,112
35Jul 27, 2024 11:067,40796,667,29725,151,00042,254,00093,229,056
36Jul 27, 2024 11:067,40797,242,18025,152,00042,255,00093,159,424