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:40Joad NacerJoad NacerScore: 3,606Success
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:403,42953,873,97822,147,0009,060,00093,130,752
2Jul 27, 2024 14:403,44152,703,00021,212,00010,101,00093,118,464
3Jul 27, 2024 14:403,44255,644,11721,221,00010,105,00093,171,712
4Jul 27, 2024 14:403,46059,174,62722,344,0009,141,00092,889,088
5Jul 27, 2024 14:403,46458,822,16022,368,0009,150,00093,102,080
6Jul 27, 2024 14:403,600105,594,14932,764,347094,498,816
7Jul 27, 2024 14:403,60694,932,18832,814,963094,502,912
8Jul 27, 2024 14:403,61391,120,25032,879,220094,502,912
9Jul 27, 2024 14:403,97558,973,59222,104,00014,066,00093,134,848
10Jul 27, 2024 14:405,82682,216,60624,009,00029,011,00093,188,096
11Jul 27, 2024 14:407,41593,039,75225,177,00042,298,00093,380,608
12Jul 27, 2024 14:407,45098,637,85125,923,00041,876,00093,102,080