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 22, 2024 01:35Joad NacerJoad NacerScore: 3,689Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2024 01:353,65359,268,83925,184,0008,059,00092,864,512
2Apr 22, 2024 01:353,65457,934,32722,169,00011,084,00092,852,224
3Apr 22, 2024 01:353,65858,129,95223,201,00010,087,00092,884,992
4Apr 22, 2024 01:353,66055,511,13025,231,0008,074,00092,930,048
5Apr 22, 2024 01:353,66758,549,89123,257,00010,112,00092,921,856
6Apr 22, 2024 01:353,67456,136,17921,276,00012,157,00093,163,520
7Apr 22, 2024 01:353,68953,787,63022,378,00011,189,00092,917,760
8Apr 22, 2024 01:353,98893,843,45936,290,052094,748,672
9Apr 22, 2024 01:353,996100,355,66136,365,602094,486,528
10Apr 22, 2024 01:354,03792,777,89936,735,181094,482,432
11Apr 22, 2024 01:354,12362,574,79822,308,00015,210,00093,151,232
12Apr 22, 2024 01:354,51768,544,77528,070,00013,032,00093,102,080