src/jdk/nashorn/internal/parser/JSONParser.java
Print this page
@@ -347,10 +347,14 @@
result = LiteralNode.newInstance(arrayToken, finish, elements);
break loop;
case COMMARIGHT:
next();
+ // check for trailing comma - not allowed in JSON
+ if (type == RBRACKET) {
+ throw error(AbstractParser.message("trailing.comma.in.json", type.getNameOrType()));
+ }
break;
default:
// Add expression element.
elements.add(jsonLiteral());
@@ -386,10 +390,14 @@
next();
break loop;
case COMMARIGHT:
next();
+ // check for trailing comma - not allowed in JSON
+ if (type == RBRACE) {
+ throw error(AbstractParser.message("trailing.comma.in.json", type.getNameOrType()));
+ }
break;
default:
// Get and add the next property.
final PropertyNode property = propertyAssignment();