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 24, 2024 20:20Joad NacerJoad NacerScore: 3,637Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 24, 2024 20:203,43351,990,79320,155,00011,085,00092,966,912
2Jun 24, 2024 20:203,49257,020,26119,859,00011,915,00092,909,568
3Jun 24, 2024 20:203,49754,008,51819,888,00011,933,00092,893,184
4Jun 24, 2024 20:203,50357,873,77419,922,00011,953,00092,897,280
5Jun 24, 2024 20:203,51058,608,09420,959,00010,978,00092,942,336
6Jun 24, 2024 20:203,614104,596,88732,884,675094,486,528
7Jun 24, 2024 20:203,637108,262,09633,094,210094,486,528
8Jun 24, 2024 20:203,63791,654,91033,098,047094,613,504
9Jun 24, 2024 20:203,93568,959,03120,886,00014,919,00093,110,272
10Jun 24, 2024 20:207,07989,769,77124,156,00040,260,00093,143,040
11Jun 24, 2024 20:207,22993,722,89623,920,00041,860,00093,343,744
12Jun 24, 2024 20:207,49089,501,12125,059,00043,102,00093,126,656