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 listJul 26, 2024 22:03Yuriy LyfenkoYuriy LyfenkoScore: 3,604Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 26, 2024 22:033,391651,557,62614,933,00015,929,00092,897,280
2Jul 26, 2024 22:033,393657,155,10115,938,00014,942,00092,876,800
3Jul 26, 2024 22:033,396655,637,42317,946,00012,961,00093,179,904
4Jul 26, 2024 22:033,404655,698,37322,714,0008,259,00093,233,152
5Jul 26, 2024 22:033,406652,574,43020,998,0009,999,00093,171,712
6Jul 26, 2024 22:033,419657,395,62821,779,0009,333,00093,085,696
7Jul 26, 2024 22:033,604687,402,91732,794,196094,613,504
8Jul 26, 2024 22:033,613693,140,22232,874,970094,638,080
9Jul 26, 2024 22:033,626703,657,15332,999,473094,609,408
10Jul 26, 2024 22:035,805673,054,32424,917,00027,908,00093,126,656
11Jul 26, 2024 22:035,972679,480,85126,168,00028,181,00093,118,464
12Jul 26, 2024 22:036,827681,906,80628,059,00034,071,00093,331,456