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 listMay 21, 2024 23:42Joad NacerJoad NacerScore: 3,725Success
Source Code

Source code access is restricted. Log in to request access.

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 21, 2024 23:423,45759,476,28321,311,00010,148,00092,958,720
2May 21, 2024 23:423,51960,483,70820,014,00012,008,00092,901,376
3May 21, 2024 23:423,52954,365,97820,069,00012,041,00092,905,472
4May 21, 2024 23:423,53156,090,74720,080,00012,048,00092,917,760
5May 21, 2024 23:423,71591,537,36633,804,112094,486,528
6May 21, 2024 23:423,71697,942,85133,812,525094,482,432
7May 21, 2024 23:423,725107,169,11733,895,166094,482,432
8May 21, 2024 23:425,09172,165,47123,165,00023,165,00093,114,368
9May 21, 2024 23:425,59387,901,02622,952,00027,942,00093,032,448
10May 21, 2024 23:425,92978,671,25322,979,00030,971,00093,138,944
11May 21, 2024 23:427,53399,456,54825,203,00043,350,00093,290,496
12May 21, 2024 23:427,55997,219,36425,921,00042,870,00093,261,824