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:36Joad NacerJoad NacerScore: 3,477Success
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:363,27059,079,34720,828,0008,926,00093,081,600
2Jul 27, 2024 14:363,35251,068,50220,338,00010,169,00093,208,576
3Jul 27, 2024 14:363,37455,747,73120,801,0009,905,00092,909,568
4Jul 27, 2024 14:363,37955,377,41519,840,00010,912,00093,212,672
5Jul 27, 2024 14:363,38154,887,75820,843,0009,925,00093,024,256
6Jul 27, 2024 14:363,43355,622,32521,164,00010,078,00093,130,752
7Jul 27, 2024 14:363,47791,923,36531,643,867094,502,912
8Jul 27, 2024 14:363,49176,648,33531,769,616094,486,528
9Jul 27, 2024 14:363,49698,672,91931,816,967094,502,912
10Jul 27, 2024 14:364,56965,018,29422,311,00019,269,00092,991,488
11Jul 27, 2024 14:364,86274,080,33521,116,00023,127,00093,241,344
12Jul 27, 2024 14:367,37689,857,85825,045,00042,075,00093,114,368