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 22:52Joad NacerJoad NacerScore: 4,490Success
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 22:524,39762,350,74228,007,00012,003,00092,860,416
2May 9, 2024 22:524,40966,148,24528,084,00012,036,00092,909,568
3May 9, 2024 22:524,42267,826,84628,170,00012,073,00092,909,568
4May 9, 2024 22:524,43061,681,42629,226,00011,086,00093,204,480
5May 9, 2024 22:524,43670,707,59429,269,00011,102,00092,872,704
6May 9, 2024 22:524,481102,390,77440,777,411094,486,528
7May 9, 2024 22:524,490102,065,00740,857,838094,482,432
8May 9, 2024 22:524,51099,323,80541,043,499094,482,432
9May 9, 2024 22:525,43677,133,99429,275,00020,190,00092,925,952
10May 9, 2024 22:526,82688,701,89031,060,00031,060,00093,011,968
11May 9, 2024 22:527,83096,522,66933,117,00038,135,00093,286,400
12May 9, 2024 22:528,389101,837,11933,147,00043,192,00093,130,752