-
-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature to allow trailing commas (non-compliant JSON) #118
Comments
+1 Even though this is getting a little far afield for acceptable representations, Jackson is pretty magical about handling other nonsense (like comments), and this would be handy. |
Datapoint: Google's "gyp" build tool uses a config file that is JSON with "#" comments and trailing commas: https://code.google.com/p/gyp/wiki/GypUserDocumentation (It's strange that they went with "#" instead of "//". Looks more like Python than JSON.) |
@cakoose FWIW, "script comments" are supported by Jackson 2.3 with I think I am actually supportive of a single trailing comma (more so than with "missing entries", that is, possible in-sequence commas), but there's still question of efficient implementation -- I do not want any measurable performance impact for the common case of no trailing commas. |
+1 for gyp it would be really great if it would be possible to parse a trailing comma |
Here's what I decided for Noggit: /** ALLOW_EXTRA_COMMAS causes any number of extra commas in arrays and objects to be ignored
* Note that a trailing comma in [] would be [,] (hence calling the feature "trailing" commas
* is either limiting or misleading. Since trailing commas is fundamentally incompatible with any future
* "fill-in-missing-values-with-null", it was decided to extend this feature to handle any
* number of extra commas.
*/
public static final int ALLOW_EXTRA_COMMAS = 1 << 5; Allowing multiple extraneous commas makes things like templating JSON easier. |
@yonik Thanks! This is useful to know wrt actual existing usage. I am still bit unsure about multiple commas, since even in templating it'd seem like two commas would suggest a missing value, which would seem more natural as |
So can a trailing comma ;-) I was coming from the point of view that it's not sane to enable "missing values" and "allow trailing comma" at the same time. Given that, if one is to allow trailing commas, one may as well allow any number of extra commas. I guess it depends on the context. For something like Solr filter lists, position does not matter, only values. If one is dealing with parallel arrays (two different arrays where the values line up), then one would want to retain the "missing" values to maintain the relative positions. But for these use-cases it seems like one would want to completely turn off trailing commas and turn on missing values. |
Yes, good point. So I think it actually would make sense to have orthogonal feature, if choice between missing value / bogus comma is important. I was thinking that a single trailing comma is most commony used at end of lists, when appending new entries, but that is probably not the only case. |
Just to record my preference here: it would be nice to have a "trailing commas" option that didn't also allow extra commas in other parts of a list. For example, if I were using Jackson on Gyp files, I'd like to be able to parse them strictly. |
I'm in a situation where a third party is sending a leading comma:
Any chance already having a feature flag similar to the ALLOW_TRAILING COMMA? Or any tips on implementing this custom deserialization? Thanks |
@albertocavalcante There is |
Splitting off from #52 and originally at http://jira.codehaus.org/browse/JACKSON-618
Presumably a feature named: ALLOW_TRAILING_COMMA
If enabled the following would be valid and yield the same result:
[1,2,3,] [1,2,3]
{1:1,} {1:1}
The text was updated successfully, but these errors were encountered: