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 28, 2023 21:46Yurkov AlekseyYurkov AlekseyScore: 12,738Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 28, 2023 21:465,956113,314,00154,199,635092,577,792
2Jul 28, 2023 21:465,963109,449,20054,263,170092,561,408
3Jul 28, 2023 21:465,977125,632,87854,389,549092,569,600
4Jul 28, 2023 21:4612,689144,198,543106,514,0008,959,00092,680,192
5Jul 28, 2023 21:4612,711142,739,525103,708,00011,966,00092,454,912
6Jul 28, 2023 21:4612,729140,064,40086,877,00028,959,00092,655,616
7Jul 28, 2023 21:4612,738138,684,83787,934,00027,979,00092,450,816
8Jul 28, 2023 21:4612,739139,712,417104,929,00010,992,00092,626,944
9Jul 28, 2023 21:4612,766137,490,386106,157,00010,014,00092,704,768
10Jul 28, 2023 21:4612,894142,224,474103,299,00014,040,00092,180,480
11Jul 28, 2023 21:4612,913148,143,067102,573,00014,937,00092,209,152
12Jul 28, 2023 21:4613,056143,835,18093,849,00024,959,00092,123,136