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 listSep 3, 2024 14:50Joad NacerJoad NacerScore: 3,264Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 3, 2024 14:503,16555,574,64118,869,0009,931,00093,159,424
2Jul 27, 2024 14:453,16751,447,23219,874,0008,943,00093,073,408
3Jul 27, 2024 14:453,17657,416,24017,937,00010,961,00093,040,640
4Sep 3, 2024 14:503,17755,892,76818,941,0009,969,00093,151,232
5Jul 27, 2024 14:453,17856,449,24417,948,00010,968,00093,040,640
6Sep 3, 2024 14:503,18355,914,06218,975,0009,987,00093,040,640
7Sep 3, 2024 14:503,22451,806,00420,235,0009,105,00093,171,712
8Jul 27, 2024 14:453,22549,994,45820,240,0009,108,00093,163,520
9Jul 27, 2024 14:453,22657,524,14420,245,0009,110,00093,048,832
10Sep 3, 2024 14:503,22948,749,15820,263,0009,118,00093,024,256
11Sep 3, 2024 14:503,23055,481,50919,256,00010,134,00092,864,512
12Jul 27, 2024 14:453,23455,457,90120,299,0009,134,00093,184,000
13Sep 3, 2024 14:503,23550,358,75520,306,0009,137,00093,048,832
14Sep 3, 2024 14:503,23655,795,56320,310,0009,139,00093,044,736
15Sep 3, 2024 14:503,23855,855,80219,306,00010,161,00093,052,928
16Jul 27, 2024 14:453,24053,115,82620,335,0009,150,00093,069,312
17Jul 27, 2024 14:453,24159,006,69519,324,00010,170,00093,032,448
18Sep 3, 2024 14:503,24355,099,97119,336,00010,176,00093,016,064
19Sep 3, 2024 14:503,24457,511,18520,356,0009,160,00093,057,024
20Jul 27, 2024 14:453,25056,939,42419,375,00010,197,00093,081,600
21Jul 27, 2024 14:453,26254,414,97219,787,0009,893,00093,081,600
22Sep 3, 2024 14:503,26456,672,63219,802,0009,901,00093,216,768
23Jul 27, 2024 14:453,26453,207,04620,790,0008,910,00092,917,760
24Jul 27, 2024 14:453,26855,119,33419,824,0009,912,00093,032,448
25Jul 27, 2024 14:453,30850,679,71320,067,00010,033,00093,163,520
26Jul 27, 2024 14:453,36186,969,85630,586,702094,502,912
27Jul 27, 2024 14:453,36383,326,62430,599,592094,498,816
28Jul 27, 2024 14:453,36885,711,91930,645,339094,507,008
29Jul 27, 2024 14:453,37096,549,20030,668,882094,498,816
30Jul 27, 2024 14:453,38587,932,85230,806,468094,498,816
31Jul 27, 2024 14:453,39493,409,27430,886,570094,494,720
32Jul 27, 2024 14:453,61063,083,53820,905,00011,946,00093,032,448
33Sep 3, 2024 14:503,84559,908,56919,995,00014,996,00093,028,352
34Jul 27, 2024 14:454,23469,865,53021,294,00017,238,00093,126,656
35Jul 27, 2024 14:455,00767,385,16420,249,00025,312,00093,216,768
36Sep 3, 2024 14:505,07974,658,35422,104,00024,114,00093,233,152
37Jul 27, 2024 14:455,09171,032,45921,150,00025,179,00093,212,672
38Sep 3, 2024 14:505,65176,440,08622,183,00029,241,00093,310,976
39Sep 3, 2024 14:506,96785,477,63323,145,00040,253,00093,237,248
40Sep 3, 2024 14:507,03589,310,70323,008,00041,015,00093,151,232
41Jul 27, 2024 14:457,25588,096,87322,007,00044,014,00093,315,072
42Sep 3, 2024 14:507,26195,121,39622,025,00044,050,00093,077,504