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 17:11AnSaAnSaScore: 4,366Success
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 17:113,61861,325,46218,955,00013,966,00092,622,848
2Jun 24, 2024 17:113,62159,668,55119,968,00012,979,00092,598,272
3Jun 24, 2024 17:113,65259,998,34919,135,00014,100,00092,594,176
4Jun 24, 2024 17:113,95967,439,17621,015,00015,011,00092,864,512
5Jun 24, 2024 17:114,14465,753,29020,840,00016,871,00092,868,608
6Jun 24, 2024 17:114,36393,017,98139,702,978094,617,600
7Jun 24, 2024 17:114,366102,644,79539,727,194094,883,840
8Jun 24, 2024 17:114,40696,363,18940,090,184094,621,696
9Jun 24, 2024 17:115,16870,750,36122,013,00025,014,00092,827,648
10Jun 24, 2024 17:118,318103,218,26720,914,00054,776,00093,134,848
11Jun 24, 2024 17:118,358107,809,87926,021,00050,041,00092,942,336
12Jun 24, 2024 17:118,461106,818,89025,998,00050,997,00093,110,272