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 9, 2024 23:50Joad NacerJoad NacerScore: 3,795Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 9, 2024 23:503,56059,218,79121,259,00011,136,00092,893,184
2May 9, 2024 23:503,58563,636,67423,451,0009,176,00093,175,808
3May 9, 2024 23:503,61161,036,43520,911,00011,949,00092,868,608
4May 9, 2024 23:503,61260,155,02220,918,00011,953,00092,860,416
5May 9, 2024 23:503,62960,492,28421,018,00012,010,00092,925,952
6May 9, 2024 23:503,779112,887,36734,388,337094,748,672
7May 9, 2024 23:503,79599,194,21234,530,062094,490,624
8May 9, 2024 23:503,811107,001,95534,675,924094,482,432
9May 9, 2024 23:504,48066,873,81222,868,00017,897,00093,077,504
10May 9, 2024 23:505,11672,574,49823,278,00023,278,00093,138,944
11May 9, 2024 23:507,00996,980,17424,914,00038,866,00093,249,536
12May 9, 2024 23:507,47495,611,59125,005,00043,009,00093,245,440