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:21Joad NacerJoad NacerScore: 3,516Success
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:213,34756,480,25920,303,00010,151,00093,065,216
2Jul 27, 2024 14:213,35956,741,65521,397,0009,170,00093,044,736
3Jul 27, 2024 14:213,37256,172,17319,794,00010,887,00092,876,800
4Jul 27, 2024 14:213,37455,370,64520,801,0009,905,00093,065,216
5Jul 27, 2024 14:213,40458,054,58520,986,0009,993,00093,028,352
6Jul 27, 2024 14:213,503106,538,93531,880,296094,629,888
7Jul 27, 2024 14:213,51663,414,60819,996,00011,997,00092,987,392
8Jul 27, 2024 14:213,52495,627,59532,065,231094,498,816
9Jul 27, 2024 14:213,53589,070,07932,168,314094,494,720
10Jul 27, 2024 14:216,36286,583,57422,956,00034,934,00093,040,640
11Jul 27, 2024 14:217,26089,102,93724,025,00042,044,00093,106,176
12Jul 27, 2024 14:217,26396,158,11025,036,00041,060,00093,241,344