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 21, 2024 23:06Joad NacerJoad NacerScore: 5,549Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 21, 2024 23:065,16071,766,77231,970,00014,986,00092,917,760
2Apr 21, 2024 23:065,18470,796,63332,116,00015,054,00092,856,320
3Apr 21, 2024 23:065,18478,342,01233,125,00014,053,00093,143,040
4Apr 21, 2024 23:065,25874,662,57131,897,00015,948,00092,958,720
5Apr 21, 2024 23:065,26072,557,83531,911,00015,955,00092,880,896
6Apr 21, 2024 23:065,28375,532,24432,051,00016,025,00092,909,568
7Apr 21, 2024 23:065,549109,749,00150,491,371094,666,752
8Apr 21, 2024 23:065,550103,337,91350,508,142094,658,560
9Apr 21, 2024 23:065,573121,009,60250,717,396094,666,752
10Apr 21, 2024 23:067,707104,345,09232,062,00038,073,00093,294,592
11Apr 21, 2024 23:067,744102,171,86034,227,00036,240,00093,065,216
12Apr 21, 2024 23:069,244106,620,69135,051,00049,072,00093,327,360