Skip to content

Commit 2f8f269

Browse files
committed
only check if property values look like JSON for parse_json: true
assume specified property names can be parsed when using `parse_json: []` form
1 parent 176927c commit 2f8f269

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

src/sources/mvt.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,28 @@ export class MVTSource extends NetworkTileSource {
128128
parseJSONProperties (feature) {
129129
if (this.parse_json_type !== PARSE_JSON_TYPE.NONE) {
130130
const props = feature.properties;
131-
for (const p in props) {
132-
// if specified, check list of explicit properties to parse
133-
// (otherwise try to parse all properties)
134-
if (this.parse_json_type === PARSE_JSON_TYPE.SOME &&
135-
this.parse_json_prop_list.indexOf(p) === -1) {
136-
continue; // skip this property
137-
}
138131

139-
// check if this property looks like JSON, and parse if so
140-
if (PARSE_JSON_TEST.indexOf(props[p][0]) > -1) {
132+
// if specified, check list of explicit properties to parse
133+
if (this.parse_json_type === PARSE_JSON_TYPE.SOME) {
134+
this.parse_json_prop_list.forEach(p => {
141135
try {
142136
props[p] = JSON.parse(props[p]);
143137
} catch (e) {
144138
// continue with original value if couldn't parse as JSON
145139
}
140+
});
141+
}
142+
// otherwise try to parse all properties
143+
else {
144+
for (const p in props) {
145+
// check if this property looks like JSON, and parse if so
146+
if (PARSE_JSON_TEST.indexOf(props[p][0]) > -1) {
147+
try {
148+
props[p] = JSON.parse(props[p]);
149+
} catch (e) {
150+
// continue with original value if couldn't parse as JSON
151+
}
152+
}
146153
}
147154
}
148155
}

0 commit comments

Comments
 (0)