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 listNov 29, 2024 13:52E SequeiraE SequeiraError
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Nov 24, 2024 18:0000000build main: cannot load encoding/json: malformed module path "encoding/json": missing dot in first path element
2Nov 29, 2024 13:521,051,3499,607,744,5489,030,767,000536,510,00094,617,600
3Nov 29, 2024 13:521,052,3409,612,058,6919,086,742,000489,555,00094,617,600
4Nov 29, 2024 13:521,052,8109,614,394,2399,099,092,000481,475,00094,588,928
5Nov 29, 2024 13:521,053,4919,624,888,7119,068,323,000518,446,00094,617,600
6Nov 29, 2024 13:521,061,4959,695,107,6939,154,145,000505,455,00094,605,312
7Nov 29, 2024 13:521,062,0369,702,742,6799,135,933,000528,591,00094,597,120
8Nov 29, 2024 13:521,070,6269,777,658,6699,152,263,000590,436,00094,617,600
9Nov 29, 2024 13:521,074,7069,821,697,8949,220,295,000559,532,00094,633,984
10Nov 29, 2024 13:521,077,3419,841,672,1309,261,253,000542,546,00094,617,600