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, 2024 12:12Yuriy LyfenkoYuriy LyfenkoScore: 3,460Success
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, 2024 12:123,313652,648,89523,116,0007,035,00093,171,712
2Jul 28, 2024 12:123,317652,469,35822,135,0008,049,00093,224,960
3Jul 28, 2024 12:123,317656,645,56321,859,0008,327,00093,093,888
4Jul 28, 2024 12:123,324658,335,70422,944,0007,300,00092,921,856
5Jul 28, 2024 12:123,329651,580,30123,229,0007,069,00093,130,752
6Jul 28, 2024 12:123,341652,776,24224,325,0006,081,00093,118,464
7Jul 28, 2024 12:123,460690,433,95231,487,474094,781,440
8Jul 28, 2024 12:123,465693,100,65531,533,902094,650,368
9Jul 28, 2024 12:123,476687,352,31931,634,748094,613,504
10Jul 28, 2024 12:125,080667,627,81428,138,00018,088,00093,155,328
11Jul 28, 2024 12:125,886680,018,11028,299,00025,267,00093,118,464
12Jul 28, 2024 12:126,149678,934,98434,974,00020,984,00093,274,112