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:49Joad NacerJoad NacerScore: 3,398Success
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:493,26961,072,09619,830,0009,915,00093,159,424
2Jul 27, 2024 14:493,28156,075,25019,902,0009,951,00093,093,888
3Jul 27, 2024 14:493,28657,638,64619,936,0009,968,00093,237,248
4Jul 27, 2024 14:493,28854,439,77519,948,0009,974,00093,065,216
5Jul 27, 2024 14:493,29861,665,36420,009,00010,004,00092,913,664
6Jul 27, 2024 14:493,38687,588,66730,811,688094,511,104
7Jul 27, 2024 14:493,39883,632,11630,921,431094,494,720
8Jul 27, 2024 14:493,41586,844,24731,073,177094,490,624
9Jul 27, 2024 14:494,19766,578,55121,108,00017,087,00093,134,848
10Jul 27, 2024 14:496,93987,776,19224,055,00039,089,00093,184,000
11Jul 27, 2024 14:497,29293,666,10824,128,00042,225,00093,229,056
12Jul 27, 2024 14:497,31996,631,98324,219,00042,383,00093,229,056