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:57Yuriy LyfenkoYuriy LyfenkoScore: 3,591Success
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:573,390658,984,70314,925,00015,920,00093,077,504
2Jul 26, 2024 21:573,395655,516,50016,479,00014,419,00092,893,184
3Jul 26, 2024 21:573,398657,594,24516,493,00014,431,00092,889,088
4Jul 26, 2024 21:573,413653,507,05630,056,0001,001,00093,171,712
5Jul 26, 2024 21:573,421655,229,85021,091,00010,043,00092,819,456
6Jul 26, 2024 21:573,565661,101,16925,348,0007,097,00092,966,912
7Jul 26, 2024 21:573,591693,276,72532,673,718094,650,368
8Jul 26, 2024 21:573,603691,607,01332,785,207094,650,368
9Jul 26, 2024 21:573,616693,435,00632,901,448094,613,504
10Jul 26, 2024 21:575,110672,992,59825,273,00021,230,00093,159,424
11Jul 26, 2024 21:576,044677,663,78231,001,00024,001,00093,114,368
12Jul 26, 2024 21:577,230690,185,05826,917,00038,880,00093,323,264