title: Convert Lua data to JSON
body: <p>This <a href="https://code.google.com/p/epgp/">EPGP World of Warcraft addon</a> outputs an epgp.lua database file.</p>
  
  <p>I wrote a <a href="https://github.com/Mottie/epgp">plugin</a> to convert the Lua data into a JSON object for display on a guild website. It was working in older versions of the addon, but now I'm having trouble trying to get it to convert the file properly. Here are two snippets that show the conversion problem - see <a href="http://jsfiddle.net/Mottie/MfncJ/">this demo</a>.</p>
  
  <p>The first works great at forming a nested array:</p>
  
  <pre><code>["roster_info"] = {
      {
          "Agantica", -- [1]
          "ROGUE", -- [2]
          "09/03-2013", -- [3]
      }, -- [1]
      {
          "Intikamim", -- [1]
          "PALADIN", -- [2]
          "17/02-2013", -- [3]
      }, -- [2]
  },
  </code></pre>
  
  <p>becomes</p>
  
  <pre><code>"roster_info" : [
      [
          "Agantica",
          "ROGUE",
          "09/03-2013"
      ],
      [
          "Intikamim",
          "PALADIN",
          "17/02-2013"
      ]
  ]
  </code></pre>
  
  <p>But the string replacment sees this next snippet as a nested array when it should be an object inside of an array:</p>
  
  <pre><code>["bonus_loot_log"] = {
      {
          ["player"] = "Magebox",
          ["timestamp"] = "2013-03-07 13:44:00",
          ["coinsLeft"] = "-1",
          ["reward"] = "|cffa335ee|Hitem:86815:0:0:0:0:0:0:632235520:90:0:445|h[Attenuating Bracers]|h|r",
      }, -- [1]
              {
          ["player"] = "Lîutasila",
          ["coinsLeft"] = "-1",
          ["timestamp"] = "2013-03-07 13:47:00",
      }, -- [2]
  },
  </code></pre>
  
  <p>becomes</p>
  
  <pre><code>"bonus_loot_log" : [
      [
          "player" : "Magebox",
          "timestamp" : "2013-03-07 13:44:00",
          "coinsLeft" : "-1",
          "reward" : "|cffa335ee|Hitem:86815:0:0:0:0:0:0:632235520:90:0:445|h[Attenuating Bracers]|h|r"
      ],
      [
          "player": "Lîutasila",
          "coinsLeft": "-1",
          "timestamp": "2013-03-07 13:47:00"
      ]
  ]
  </code></pre>
  
  <p>Here is the string conversion script that only works on the first snippet.</p>
  
  <pre><code>lua_string
      .replace(/\[(.*)\]\s\=\s/g,'$1:')     // change equal to colon &amp; remove outer brackets
      .replace(/[\t\r\n]/g,'')              // remove tabs &amp; returns
      .replace(/\}\,\s--\s\[\d+\]\}/g,']]') // replace sets ending with a comment with square brackets
      .replace(/\,\s--\s\[\d+\]/g,',')      // remove close subgroup and comment
      .replace(/,(\}|\])/g,'$1')            // remove trailing comma
      .replace(/\}\,\{/g,'],[')             // replace curly bracket set with square brackets
      .replace(/\{\{/g,'[[')                // change double curlies to square brackets
      .replace(/EPGP_DB\s\=/,'');
  </code></pre>
  
  <p>So, I need some help getting the Lua to convert properly with an array of objects (second example).</p>