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 21, 2024 23:08Joad NacerJoad NacerScore: 5,004Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 21, 2024 23:084,71070,090,08731,900,00010,965,00092,889,088
2Apr 21, 2024 23:084,73870,669,48033,087,00010,026,00092,938,240
3Apr 21, 2024 23:084,77567,174,88233,345,00010,104,00092,934,144
4Apr 21, 2024 23:084,77669,800,14332,344,00011,118,00092,880,896
5Apr 21, 2024 23:084,79870,251,02632,490,00011,168,00092,897,280
6Apr 21, 2024 23:084,80867,652,58731,818,00011,932,00092,962,816
7Apr 21, 2024 23:085,004106,357,31545,538,279094,482,432
8Apr 21, 2024 23:085,007116,889,29545,566,358094,494,720
9Apr 21, 2024 23:085,009118,151,70445,584,950094,482,432
10Apr 21, 2024 23:085,33368,746,35832,352,00016,176,00093,200,384
11Apr 21, 2024 23:085,51378,001,21433,109,00017,056,00093,020,160
12Apr 21, 2024 23:087,44197,946,51735,846,00031,863,00093,220,864