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:15Joad NacerJoad NacerScore: 3,906Success
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:153,82960,495,20423,892,00010,950,00092,876,800
2Apr 22, 2024 01:153,83961,691,70424,955,0009,982,00092,905,472
3Apr 22, 2024 01:153,84259,931,56323,974,00010,988,00092,844,032
4Apr 22, 2024 01:153,88058,329,50825,223,00010,089,00092,864,512
5Apr 22, 2024 01:153,88156,389,44624,219,00011,100,00092,975,104
6Apr 22, 2024 01:153,89862,285,87224,324,00011,148,00092,950,528
7Apr 22, 2024 01:153,90665,613,00725,391,00010,156,00092,901,376
8Apr 22, 2024 01:154,089105,049,01137,211,920094,486,528
9Apr 22, 2024 01:154,09594,848,06437,264,259094,494,720
10Apr 22, 2024 01:154,098101,108,34037,291,839094,494,720
11Apr 22, 2024 01:154,71064,098,90924,918,00017,941,00093,192,192
12Apr 22, 2024 01:154,80974,544,47323,871,00019,892,00093,167,616