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 listJun 24, 2024 20:20Joad NacerJoad NacerScore: 3,587Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 24, 2024 20:203,41958,889,74920,071,00011,039,00092,966,912
2Jun 24, 2024 20:203,47959,642,27419,789,00011,873,00093,196,288
3Jun 24, 2024 20:203,48157,837,05520,789,00010,889,00092,901,376
4Jun 24, 2024 20:203,49358,029,38419,867,00011,920,00092,880,896
5Jun 24, 2024 20:203,49463,154,90719,870,00011,922,00092,835,840
6Jun 24, 2024 20:203,50058,991,70619,904,00011,942,00092,938,240
7Jun 24, 2024 20:203,587119,654,67932,643,237094,498,816
8Jun 24, 2024 20:203,62796,398,97333,004,748094,490,624
9Jun 24, 2024 20:203,638101,705,88533,103,640094,478,336
10Jun 24, 2024 20:207,04595,161,04325,044,00039,068,00093,200,384
11Jun 24, 2024 20:207,15599,987,48424,039,00041,067,00093,106,176
12Jun 24, 2024 20:207,44499,115,34323,908,00043,831,00093,315,072