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 listMay 22, 2024 00:56Joad NacerJoad NacerScore: 3,754Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 22, 2024 00:563,49358,702,44020,861,00010,927,00092,930,048
2May 22, 2024 00:563,50660,131,07021,935,0009,970,00092,942,336
3May 22, 2024 00:563,54556,046,50520,164,00012,098,00093,155,328
4May 22, 2024 00:563,59365,879,83320,805,00011,888,00092,864,512
5May 22, 2024 00:563,719116,311,09933,841,436094,482,432
6May 22, 2024 00:563,73596,577,79133,990,143094,486,528
7May 22, 2024 00:563,75490,357,37834,158,194094,625,792
8May 22, 2024 00:565,02071,387,64921,847,00023,833,00093,130,752
9May 22, 2024 00:565,20576,441,45423,177,00024,185,00093,130,752
10May 22, 2024 00:567,41897,966,61125,187,00042,314,00093,323,264
11May 22, 2024 00:567,49089,844,21226,062,00042,101,00093,270,016
12May 22, 2024 00:567,57898,731,63625,986,00042,977,00093,286,400