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:36Yuriy LyfenkoYuriy LyfenkoScore: 3,598Success
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:363,394559,657,75615,941,00014,945,00092,864,512
2Jul 26, 2024 21:363,397559,433,98421,642,0009,275,00093,028,352
3Jul 26, 2024 21:363,398562,113,80214,962,00015,960,00092,876,800
4Jul 26, 2024 21:363,407553,128,61118,003,00013,002,00093,048,832
5Jul 26, 2024 21:363,574555,714,69220,325,00012,195,00092,971,008
6Jul 26, 2024 21:363,590598,639,44632,671,868094,650,368
7Jul 26, 2024 21:363,598592,965,10732,742,949094,650,368
8Jul 26, 2024 21:363,612597,549,84032,866,110094,609,408
9Jul 26, 2024 21:364,694571,495,70021,853,00020,860,00093,175,808
10Jul 26, 2024 21:364,938568,452,15924,967,00019,973,00093,167,616
11Jul 26, 2024 21:367,146587,411,49727,010,00038,015,00093,319,168
12Jul 26, 2024 21:367,297590,662,00031,189,00035,213,00093,323,264