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:55Joad NacerJoad NacerScore: 3,432Success
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:553,23553,180,89720,302,0009,136,00092,946,432
2Jul 27, 2024 14:553,24156,409,09920,340,0009,153,00093,163,520
3Jul 27, 2024 14:553,30350,151,16420,040,00010,020,00093,204,480
4Jul 27, 2024 14:553,30555,950,31320,051,00010,025,00093,061,120
5Jul 27, 2024 14:553,30951,388,87220,075,00010,037,00092,901,376
6Jul 27, 2024 14:553,42782,893,17731,189,176094,502,912
7Jul 27, 2024 14:553,43297,882,85731,227,671094,502,912
8Jul 27, 2024 14:553,43590,490,88131,255,904094,494,720
9Jul 27, 2024 14:554,81573,665,00420,911,00022,903,00093,106,176
10Jul 27, 2024 14:555,97179,531,16323,143,00031,192,00093,061,120
11Jul 27, 2024 14:556,02381,880,03222,921,00031,890,00093,233,152
12Jul 27, 2024 14:557,20092,756,27624,192,00041,328,00093,081,600