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 28, 2024 12:52Yuriy LyfenkoYuriy LyfenkoScore: 5,485Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 28, 2024 12:523,685662,313,42422,682,00010,848,00093,208,576
2Jul 28, 2024 12:523,699661,049,97424,752,0008,911,00092,884,992
3Jul 28, 2024 12:523,703654,207,49226,758,0006,937,00093,159,424
4Jul 28, 2024 12:524,111691,770,58237,407,180094,650,368
5Jul 28, 2024 12:524,115696,455,97537,449,871094,613,504
6Jul 28, 2024 12:524,123694,860,84137,520,130094,613,504
7Jul 28, 2024 12:525,485670,593,38326,955,00022,962,00093,155,328
8Jul 28, 2024 12:525,650668,260,99730,848,00020,565,00093,147,136
9Jul 28, 2024 12:526,088680,023,95530,218,00025,182,00093,126,656
10Jul 28, 2024 12:527,428696,992,58732,282,00035,309,00093,057,024
11Jul 28, 2024 12:527,429697,561,67530,731,00036,877,00093,229,056
12Jul 28, 2024 12:527,452695,024,70127,922,00039,888,00093,061,120