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:20Joad NacerJoad NacerScore: 3,853Success
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:203,77056,854,18923,206,00011,098,00092,897,280
2Apr 22, 2024 01:203,77560,311,13123,237,00011,113,00093,200,384
3Apr 22, 2024 01:203,78857,942,39224,334,00010,139,00092,934,144
4Apr 22, 2024 01:203,81660,743,70123,812,00010,914,00092,889,088
5Apr 22, 2024 01:203,82359,188,29322,859,00011,926,00092,921,856
6Apr 22, 2024 01:203,83860,967,30722,952,00011,975,00092,913,664
7Apr 22, 2024 01:203,85364,029,22823,042,00012,022,00093,024,256
8Apr 22, 2024 01:203,97698,186,67736,185,402094,486,528
9Apr 22, 2024 01:203,984119,896,23936,251,447094,490,624
10Apr 22, 2024 01:204,017106,318,58936,556,629094,617,600
11Apr 22, 2024 01:204,39369,401,76723,986,00015,990,00093,192,192
12Apr 22, 2024 01:205,91879,533,95424,933,00028,923,00093,102,080