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 listApr 22, 2024 02:22Yuriy LyfenkoYuriy LyfenkoScore: 3,665Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2024 02:223,385558,402,79713,913,00016,894,00092,905,472
2Apr 22, 2024 02:223,388558,612,96213,925,00016,909,00092,938,240
3Apr 22, 2024 02:223,396559,237,69222,932,0007,976,00092,917,760
4Apr 22, 2024 02:223,398558,751,25614,962,00015,960,00092,872,704
5Apr 22, 2024 02:223,406564,020,92713,997,00016,997,00093,040,640
6Apr 22, 2024 02:223,423561,038,36128,138,0003,014,00092,909,568
7Apr 22, 2024 02:223,665592,420,15333,352,835094,609,408
8Apr 22, 2024 02:223,672597,207,79733,414,537094,609,408
9Apr 22, 2024 02:223,700605,192,46633,673,049094,601,216
10Apr 22, 2024 02:224,054565,274,05714,346,00022,544,00092,909,568
11Apr 22, 2024 02:224,157569,809,20115,133,00022,699,00092,884,992
12Apr 22, 2024 02:224,286566,501,40317,919,00021,082,00092,856,320