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:05Joad NacerJoad NacerScore: 5,534Success
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:054,92174,558,22431,844,00012,936,00092,876,800
2Apr 21, 2024 23:054,92770,229,77630,890,00013,950,00092,905,472
3Apr 21, 2024 23:054,93572,557,63330,936,00013,971,00092,901,376
4Apr 21, 2024 23:054,93873,030,49730,954,00013,979,00092,950,528
5Apr 21, 2024 23:054,94771,820,61830,014,00015,007,00092,917,760
6Apr 21, 2024 23:054,95569,862,97231,064,00014,029,00092,909,568
7Apr 21, 2024 23:055,534108,678,51550,360,674094,621,696
8Apr 21, 2024 23:055,537114,320,93250,386,125094,879,744
9Apr 21, 2024 23:055,544109,003,62350,448,951094,617,600
10Apr 21, 2024 23:056,26479,835,53036,001,00021,000,00093,151,232
11Apr 21, 2024 23:056,59586,875,39037,010,00023,006,00093,118,464
12Apr 21, 2024 23:057,36792,568,48532,021,00035,023,00093,118,464