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 23, 2024 22:23Joad NacerJoad NacerScore: 4,096Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 23, 2024 22:233,73559,862,94921,991,00011,995,00092,966,912
2Apr 23, 2024 22:233,74164,143,76423,031,00011,015,00092,884,992
3Apr 23, 2024 22:233,75656,412,03724,127,00010,052,00093,003,776
4Apr 23, 2024 22:233,77060,306,30024,216,00010,090,00092,954,624
5Apr 23, 2024 22:233,77666,351,70523,247,00011,118,00092,917,760
6Apr 23, 2024 22:234,093102,532,53237,244,601094,478,336
7Apr 23, 2024 22:234,09697,511,44637,273,410094,601,216
8Apr 23, 2024 22:234,11896,859,41537,471,849094,609,408
9Apr 23, 2024 22:234,49274,694,23722,930,00017,945,00093,077,504
10Apr 23, 2024 22:236,35287,515,56527,903,00029,897,00093,278,208
11Apr 23, 2024 22:237,37891,990,03034,073,00033,071,00093,069,312
12Apr 23, 2024 22:237,80495,595,42129,005,00042,008,00093,257,728