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:14Joad NacerJoad NacerScore: 3,661Success
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:143,43852,492,09921,192,00010,091,00092,897,280
2May 22, 2024 00:143,44460,397,51921,232,00010,110,00092,962,816
3May 22, 2024 00:143,45258,260,56621,277,00010,132,00092,889,088
4May 22, 2024 00:143,51557,677,68019,993,00011,996,00092,889,088
5May 22, 2024 00:143,53063,509,72521,083,00011,043,00093,212,672
6May 22, 2024 00:143,64995,067,87333,205,671094,486,528
7May 22, 2024 00:143,66191,824,38033,311,175094,486,528
8May 22, 2024 00:143,664104,271,39933,344,646094,486,528
9May 22, 2024 00:144,67267,689,76322,268,00020,244,00093,069,312
10May 22, 2024 00:147,36891,507,64524,017,00043,031,00093,327,360
11May 22, 2024 00:147,41897,036,81725,188,00042,317,00093,278,208
12May 22, 2024 00:147,56896,682,10324,952,00043,917,00093,188,096