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:05Yuriy LyfenkoYuriy LyfenkoScore: 4,249Success
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:053,395655,541,15416,478,00014,418,00092,913,664
2Jul 26, 2024 22:053,401653,810,85715,975,00014,976,00093,155,328
3Jul 26, 2024 22:053,426650,707,63522,124,0009,051,00093,147,136
4Jul 26, 2024 22:053,596696,714,46632,727,592094,642,176
5Jul 26, 2024 22:053,600697,336,03632,756,428094,609,408
6Jul 26, 2024 22:053,614699,392,74332,883,416094,654,464
7Jul 26, 2024 22:054,249663,519,97017,844,00020,818,00093,196,288
8Jul 26, 2024 22:054,697667,612,39021,867,00020,873,00093,175,808
9Jul 26, 2024 22:054,872666,755,35526,196,00018,136,00093,171,712
10Jul 26, 2024 22:057,139684,836,58132,980,00031,981,00093,319,168
11Jul 26, 2024 22:057,142689,929,44634,996,00029,996,00093,323,264
12Jul 26, 2024 22:057,147685,838,80129,469,00035,566,00093,233,152