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 14:18Joad NacerJoad NacerScore: 3,497Success
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 14:173,31352,067,36020,096,00010,048,00093,007,872
2Jul 27, 2024 14:183,34454,856,14120,287,00010,143,00093,102,080
3Jul 27, 2024 14:183,34851,627,78020,311,00010,155,00092,864,512
4Jul 27, 2024 14:183,34861,462,03521,325,0009,139,00093,028,352
5Jul 27, 2024 14:183,35355,606,31420,670,0009,843,00093,130,752
6Jul 27, 2024 14:183,35652,918,76121,381,0009,163,00093,085,696
7Jul 27, 2024 14:183,35655,377,33421,378,0009,162,00093,204,480
8Jul 27, 2024 14:173,35954,284,16120,379,00010,189,00093,028,352
9Jul 27, 2024 14:183,35957,505,66720,378,00010,189,00092,880,896
10Jul 27, 2024 14:173,36058,700,66620,383,00010,191,00092,876,800
11Jul 27, 2024 14:173,36359,463,85721,422,0009,181,00093,151,232
12Jul 27, 2024 14:183,38258,375,03420,851,0009,929,00093,081,600
13Jul 27, 2024 14:173,38752,855,43820,880,0009,943,00092,930,048
14Jul 27, 2024 14:183,38857,845,71120,888,0009,946,00093,179,904
15Jul 27, 2024 14:183,46992,759,50731,569,825094,498,816
16Jul 27, 2024 14:173,47295,491,81431,591,279094,765,056
17Jul 27, 2024 14:183,479100,963,31831,655,693094,507,008
18Jul 27, 2024 14:183,49091,200,28331,762,359094,507,008
19Jul 27, 2024 14:183,49798,301,67331,821,581094,543,872
20Jul 27, 2024 14:183,49985,867,04031,838,129094,494,720
21Jul 27, 2024 14:173,50096,176,40231,850,574094,625,792
22Jul 27, 2024 14:173,50097,457,91431,850,259094,625,792
23Jul 27, 2024 14:183,505105,415,21131,893,369094,511,104
24Jul 27, 2024 14:173,90857,980,47421,338,00014,225,00093,102,080
25Jul 27, 2024 14:184,44867,768,82020,237,00020,237,00093,036,544
26Jul 27, 2024 14:184,91668,676,40021,870,00022,864,00093,089,792
27Jul 27, 2024 14:175,12774,307,79022,313,00024,341,00093,204,480
28Jul 27, 2024 14:175,22373,925,68322,247,00025,281,00093,233,152
29Jul 27, 2024 14:185,58576,967,79321,923,00028,899,00093,188,096
30Jul 27, 2024 14:185,80776,956,27221,937,00030,911,00093,179,904
31Jul 27, 2024 14:185,92482,446,45022,962,00030,949,00093,253,632
32Jul 27, 2024 14:185,93378,940,99422,995,00030,993,00093,270,016
33Jul 27, 2024 14:177,23391,681,45324,933,00040,891,00093,298,688
34Jul 27, 2024 14:187,27391,680,21924,067,00042,118,00093,151,232
35Jul 27, 2024 14:187,35095,977,77823,959,00042,928,00093,155,328
36Jul 27, 2024 14:187,35989,024,93823,988,00042,978,00093,204,480