D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3415 - broken JSON output
Summary: broken JSON output
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86_64 Linux
: P2 minor
Assignee: No Owner
URL:
Keywords: patch
: 3440 (view as issue list)
Depends on:
Blocks:
 
Reported: 2009-10-17 15:16 UTC by briancschott
Modified: 2014-04-18 09:12 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description briancschott 2009-10-17 15:16:41 UTC
Items in arrays output by the -X option of dmd are not properly separated by commas. The most common example of this is class member functions.

Example:

...
"members" : [
{
"name" : "drawLayer",
"kind" : "function",
"type" : "void(uint layer, int x, int y)",
"line" : 133}
{
"name" : "drawAllLayers",
"kind" : "function",
"type" : "void(int x, int y)",
"line" : 149}
...

Should read:

...
"members" : [
{
"name" : "drawLayer",
"kind" : "function",
"type" : "void(uint layer, int x, int y)",
"line" : 133},
{
"name" : "drawAllLayers",
"kind" : "function",
"type" : "void(int x, int y)",
"line" : 149},
...

The lack of commas causes the resulting files to fail validation and attempts at parsing. See: http://www.jsonlint.com/
Comment 1 Ary Borenszweig 2009-10-26 01:01:09 UTC
*** Issue 3440 has been marked as a duplicate of this issue. ***
Comment 2 Rainer Schuetze 2010-04-14 00:04:47 UTC
This happens for declarations in an AttribDeclaration, where the code for adding commas is missing. Here's the patch:

Index: json.c
===================================================================
--- json.c	(revision 432)
+++ json.c	(working copy)
@@ -214,11 +214,17 @@
 
     if (d)
     {
+        size_t offset = buf->offset;
         for (unsigned i = 0; i < d->dim; i++)
         {   Dsymbol *s = (Dsymbol *)d->data[i];
+            if (offset != buf->offset)
+            {   buf->writestring(",\n");
+                offset = buf->offset;
+            }
             //printf("AttribDeclaration::toJsonBuffer %s\n", s->toChars());
             s->toJsonBuffer(buf);
         }
+        JsonRemoveComma(buf);
     }
 }
Comment 3 Don 2010-05-05 19:06:53 UTC
Fixed DMD2.044