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 listApr 22, 2024 01:48Joad NacerJoad NacerScore: 4,086Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2024 01:483,84164,469,11123,970,00010,986,00092,958,720
2Apr 22, 2024 01:483,85758,955,34724,068,00011,031,00092,909,568
3Apr 22, 2024 01:483,91462,131,65624,426,00011,195,00092,966,912
4Apr 22, 2024 01:483,93063,776,26124,521,00011,238,00092,876,800
5Apr 22, 2024 01:483,93165,127,14623,849,00011,924,00092,905,472
6Apr 22, 2024 01:483,93961,973,46123,895,00011,947,00092,889,088
7Apr 22, 2024 01:484,08696,053,88737,184,184094,613,504
8Apr 22, 2024 01:484,102118,199,56037,326,888094,490,624
9Apr 22, 2024 01:484,10595,647,42437,359,133094,494,720
10Apr 22, 2024 01:485,27570,730,45726,004,00022,003,00093,171,712
11Apr 22, 2024 01:485,55478,020,01326,283,00024,261,00093,134,848
12Apr 22, 2024 01:486,45686,285,53027,882,00030,870,00093,057,024