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 29, 2023 10:26Yurkov AlekseyYurkov AlekseyScore: 12,973Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 29, 2023 10:266,179113,332,55356,225,190092,553,216
2Jul 29, 2023 10:266,180124,929,50956,239,508092,561,408
3Jul 29, 2023 10:266,202118,298,92556,437,422092,565,504
4Jul 29, 2023 10:2612,926144,274,786102,674,00014,952,00092,692,480
5Jul 29, 2023 10:2612,928140,957,630100,700,00016,949,00092,708,864
6Jul 29, 2023 10:2612,952140,986,868100,886,00016,980,00092,704,768
7Jul 29, 2023 10:2612,973146,554,560102,044,00016,006,00092,463,104
8Jul 29, 2023 10:2613,001139,544,882103,267,00015,038,00091,947,008
9Jul 29, 2023 10:2613,001142,347,760102,271,00016,042,00092,700,672
10Jul 29, 2023 10:2613,003141,899,863104,286,00014,038,00092,471,296
11Jul 29, 2023 10:2613,015140,402,27999,525,00018,909,00092,168,192
12Jul 29, 2023 10:2613,162142,375,17599,811,00019,962,00092,110,848