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 21:33Yuriy LyfenkoYuriy LyfenkoScore: 3,644Success
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 21:333,496560,438,18922,868,0008,948,00093,097,984
2Jul 26, 2024 21:333,500560,862,55822,890,0008,957,00093,143,040
3Jul 26, 2024 21:333,504562,030,59322,917,0008,967,00093,184,000
4Jul 26, 2024 21:333,516557,518,02821,000,00011,000,00093,220,864
5Jul 26, 2024 21:333,517557,098,55023,002,0009,001,00093,044,736
6Jul 26, 2024 21:333,636586,324,20733,083,451094,633,984
7Jul 26, 2024 21:333,644590,990,00033,161,338094,613,504
8Jul 26, 2024 21:333,651591,422,26233,222,247094,654,464
9Jul 26, 2024 21:335,163570,527,95625,989,00020,991,00093,073,408
10Jul 26, 2024 21:335,756577,504,89931,840,00020,542,00093,134,848
11Jul 26, 2024 21:336,960585,751,46932,170,00031,164,00093,077,504
12Jul 26, 2024 21:337,304596,987,36327,190,00039,275,00093,323,264