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 listApr 30, 2025 23:29Aniruddha DebAniruddha DebScore: 6,064Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 30, 2025 23:326,03077,996,53845,892,0008,979,00094,404,608
2Apr 30, 2025 23:326,03881,059,24547,953,0006,993,00094,560,256
3Apr 30, 2025 23:296,04682,234,25747,019,0008,003,00094,392,320
4Apr 30, 2025 23:296,04774,840,15850,027,0005,002,00094,519,296
5Apr 30, 2025 23:326,05273,632,56247,064,0008,011,00094,412,800
6Apr 30, 2025 23:326,05279,148,13248,064,0007,009,00094,511,104
7Apr 30, 2025 23:326,05476,316,93649,080,0006,009,00094,556,160
8Apr 30, 2025 23:326,05778,511,11647,102,0008,017,00094,498,816
9Apr 30, 2025 23:296,06178,268,53450,144,0005,014,00094,441,472
10Apr 30, 2025 23:296,06276,723,83046,135,0009,026,00094,552,064
11Apr 30, 2025 23:326,06481,636,75848,161,0007,023,00094,543,872
12Apr 30, 2025 23:326,06576,351,60746,160,0009,031,00094,625,792
13Apr 30, 2025 23:296,06580,582,56248,166,0007,024,00094,527,488
14Apr 30, 2025 23:326,06879,603,57148,188,0007,027,00094,601,216
15Apr 30, 2025 23:296,06976,703,93347,193,0008,032,00094,609,408
16Apr 30, 2025 23:296,06978,258,07547,193,0008,032,00094,412,800
17Apr 30, 2025 23:326,07177,452,95748,217,0007,031,00094,531,584
18Apr 30, 2025 23:326,07381,603,37247,227,0008,038,00094,629,888
19Apr 30, 2025 23:296,07476,717,92347,230,0008,039,00094,674,944
20Apr 30, 2025 23:326,07782,929,79446,251,0009,049,00094,384,128
21Apr 30, 2025 23:296,08077,937,55148,288,0007,042,00094,638,080