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 22:01Yuriy LyfenkoYuriy LyfenkoScore: 3,666Success
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 22:013,481656,063,26421,458,00010,218,00092,897,280
2Jul 26, 2024 22:013,488656,569,89721,824,0009,920,00093,188,096
3Jul 26, 2024 22:013,499658,888,17521,888,0009,949,00092,938,240
4Jul 26, 2024 22:013,500655,335,65023,889,0007,963,00092,913,664
5Jul 26, 2024 22:013,500658,390,52422,895,0008,959,00092,872,704
6Jul 26, 2024 22:013,664709,868,57433,339,014094,609,408
7Jul 26, 2024 22:013,666691,009,18033,362,969094,650,368
8Jul 26, 2024 22:013,678690,294,69833,472,628094,613,504
9Jul 26, 2024 22:013,966663,164,39525,065,00011,028,00092,954,624
10Jul 26, 2024 22:016,430685,562,48127,237,00031,273,00093,097,984
11Jul 26, 2024 22:016,511680,768,01328,117,00031,130,00093,356,032
12Jul 26, 2024 22:017,017688,938,72835,916,00027,935,00093,065,216