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,381Success
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,24855,686,17721,402,0008,153,00092,917,760
2Jul 27, 2024 14:493,28159,007,54719,907,0009,953,00092,909,568
3Jul 27, 2024 14:493,30553,192,06619,050,00011,029,00092,925,952
4Jul 27, 2024 14:493,31353,027,86420,101,00010,050,00092,909,568
5Jul 27, 2024 14:493,33349,369,32921,234,0009,100,00093,081,600
6Jul 27, 2024 14:493,33459,714,43821,237,0009,101,00093,028,352
7Jul 27, 2024 14:493,381105,267,38330,766,114094,498,816
8Jul 27, 2024 14:493,383106,784,26830,789,524094,511,104
9Jul 27, 2024 14:493,40288,270,05230,959,026094,494,720
10Jul 27, 2024 14:493,68559,467,72820,321,00013,209,00093,106,176
11Jul 27, 2024 14:494,94071,515,94919,980,00024,975,00093,081,600
12Jul 27, 2024 14:495,68580,270,78221,889,00029,848,00093,274,112