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 listJun 23, 2024 15:51AnSaAnSaScore: 7,334Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 23, 2024 15:524,53762,654,02329,206,00012,085,00091,873,280
2Jun 23, 2024 15:514,54167,882,75626,206,00015,119,00091,930,624
3Jun 23, 2024 15:524,55069,742,87928,276,00013,128,00091,869,184
4Jun 23, 2024 15:514,55164,183,09429,290,00012,120,00091,873,280
5Jun 23, 2024 15:514,55269,353,53830,307,00011,112,00091,893,760
6Jun 23, 2024 15:524,56067,044,71430,364,00011,133,00092,188,672
7Jun 23, 2024 15:525,06978,986,75528,080,00018,051,00091,914,240
8Jun 23, 2024 15:525,09975,669,00028,244,00018,157,00092,160,000
9Jun 23, 2024 15:525,16579,437,50728,004,00019,002,00092,172,288
10Jun 23, 2024 15:515,43885,059,90429,286,00020,197,00092,168,192
11Jun 23, 2024 15:515,66883,439,62230,340,00021,238,00092,139,520
12Jun 23, 2024 15:517,01285,272,35132,901,00030,907,00092,102,656
13Jun 23, 2024 15:517,334136,197,71066,743,534092,520,448
14Jun 23, 2024 15:527,337130,593,33566,763,203092,651,520
15Jun 23, 2024 15:517,340133,902,17766,791,485092,524,544
16Jun 23, 2024 15:527,357126,927,17866,948,015092,532,736
17Jun 23, 2024 15:517,358130,353,64966,961,224092,524,544
18Jun 23, 2024 15:527,368125,306,76567,046,762092,663,808
19Jun 23, 2024 15:529,498117,258,54041,205,00045,225,00092,405,760
20Jun 23, 2024 15:529,502119,910,45937,203,00049,269,00092,393,472
21Jun 23, 2024 15:529,507115,396,36040,238,00046,273,00092,233,728
22Jun 23, 2024 15:519,550113,650,69631,964,00054,938,00092,364,800
23Jun 23, 2024 15:519,596117,705,98534,125,00053,195,00092,352,512
24Jun 23, 2024 15:519,640119,197,35437,882,00049,845,00092,254,208