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 listJul 27, 2024 14:22Joad NacerJoad NacerScore: 3,501Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 27, 2024 14:223,29757,106,28919,002,00011,001,00093,122,560
2Jul 27, 2024 14:223,36955,317,40020,771,0009,891,00093,089,792
3Jul 27, 2024 14:223,37060,506,92219,784,00010,881,00093,061,120
4Jul 27, 2024 14:223,37156,863,77021,770,0008,906,00092,876,800
5Jul 27, 2024 14:223,37354,303,86021,485,0009,207,00093,040,640
6Jul 27, 2024 14:223,48384,223,68231,698,990094,498,816
7Jul 27, 2024 14:223,50197,815,85531,859,685094,502,912
8Jul 27, 2024 14:223,501104,573,59931,859,515094,494,720
9Jul 27, 2024 14:224,12558,198,99222,318,00015,217,00093,134,848
10Jul 27, 2024 14:225,76079,460,98123,185,00029,233,00093,253,632
11Jul 27, 2024 14:227,26088,620,61724,023,00042,041,00093,126,656
12Jul 27, 2024 14:227,350101,058,66623,960,00042,929,00093,122,560