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:30Yuriy LyfenkoYuriy LyfenkoScore: 5,871Success
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:303,313653,804,92922,106,0008,038,00093,171,712
2Jul 28, 2024 12:303,325651,008,19923,998,0006,260,00093,032,448
3Jul 28, 2024 12:303,341654,202,37524,323,0006,080,00093,159,424
4Jul 28, 2024 12:303,458704,905,09031,469,817094,650,368
5Jul 28, 2024 12:303,466692,740,63431,540,255094,609,408
6Jul 28, 2024 12:303,473691,064,53131,606,112094,642,176
7Jul 28, 2024 12:305,871680,373,89523,632,00029,797,00093,118,464
8Jul 28, 2024 12:306,143678,490,70121,345,00034,559,00093,360,128
9Jul 28, 2024 12:306,144677,706,02523,961,00031,948,00093,110,272
10Jul 28, 2024 12:307,005689,587,79231,872,00031,872,00093,327,360
11Jul 28, 2024 12:307,072685,921,44524,133,00040,222,00093,319,168
12Jul 28, 2024 12:307,076686,180,85641,253,00023,142,00093,323,264