Skip to content

Commit

Permalink
Fix parsing json where the array is at the middle of a json object
Browse files Browse the repository at this point in the history
  • Loading branch information
nmeylan committed Jul 17, 2024
1 parent e99fca9 commit 5f67116
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ eframe = { version = "0.28.1", default-features = false, features = [
"x11"] }
egui = { version = "0.28.1", default-features = false, features = [] }
egui_extras = { version = "0.28.1", default-features = false, features = ["svg"] }
json-flat-parser = {git = "https://github.com/nmeylan/json-parser-flat-format.git", rev = "c652033", features = ["indexmap", "simdutf8", "serde"]}
json-flat-parser = {git = "https://github.com/nmeylan/json-parser-flat-format.git", rev = "1ba7441", features = ["indexmap", "simdutf8", "serde"]}
rayon = {version = "1.10.0"}
rfd = {version = "0.14.1"}
indexmap = "2.2.6"
Expand Down
20 changes: 16 additions & 4 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,26 @@ pub fn change_depth_array<'array>(previous_parse_result: ParseResult<String>, mu
Ok((mem::take(&mut new_json_array_guard), unique_keys, 4))
}
pub fn as_array<'array>(mut previous_parse_result: ParseResult<String>) -> Result<(Vec<JsonArrayEntries<String>>, Vec<Column<'array>>), String> {
if !matches!(previous_parse_result.json[0].pointer.value_type, ValueType::Array(_)) {
let (root_value, start_index, mut end_index) = if let Some(ref started_parsing_at) = previous_parse_result.started_parsing_at {
let mut root_value = previous_parse_result.json[previous_parse_result.started_parsing_at_index_start].clone();
(root_value, previous_parse_result.started_parsing_at_index_start, previous_parse_result.started_parsing_at_index_end)
} else {
(previous_parse_result.json[0].clone(), 0, 0)
};

if !matches!(root_value.pointer.value_type, ValueType::Array(_)) {
return Err("Parsed json root is not an array".to_string());
}
let root_array_len = match previous_parse_result.json[0].pointer.value_type {
let root_array_len = match root_value.pointer.value_type {
ValueType::Array(root_array_len) => root_array_len,
_ => panic!("")
};
if end_index == 0 {
end_index = previous_parse_result.json.len() - 1;
}
let mut unique_keys: Vec<Column> = Vec::with_capacity(16);
let mut res: Vec<JsonArrayEntries<String>> = Vec::with_capacity(root_array_len);
let mut j = previous_parse_result.json.len() - 1;
let mut j = end_index;
let estimated_capacity = 16;
for i in (0..root_array_len).rev() {
let mut flat_json_values: Vec<FlatJsonValue<String>> = Vec::with_capacity(estimated_capacity);
Expand Down Expand Up @@ -190,7 +200,9 @@ pub fn as_array<'array>(mut previous_parse_result: ParseResult<String>) -> Resul
break;
}
}
res.push(JsonArrayEntries::<String> { entries: flat_json_values, index: i });
if !flat_json_values.is_empty() {
res.push(JsonArrayEntries::<String> { entries: flat_json_values, index: i });
}
}
res.reverse();
unique_keys.sort();
Expand Down
30 changes: 15 additions & 15 deletions web/json-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function makeMutClosure(arg0, arg1, dtor, f) {
return real;
}
function __wbg_adapter_28(arg0, arg1) {
wasm.wasm_bindgen__convert__closures__invoke0_mut__h5f2f14d0e5bf9f7d(arg0, arg1);
wasm.wasm_bindgen__convert__closures__invoke0_mut__h2d5dad65975d3dc3(arg0, arg1);
}

function __wbg_adapter_31(arg0, arg1) {
Expand Down Expand Up @@ -404,10 +404,6 @@ function __wbg_get_imports() {
const ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
const ret = getObject(arg0);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_cb_drop = function(arg0) {
const obj = takeObject(arg0).original;
if (obj.cnt-- == 1) {
Expand All @@ -417,6 +413,10 @@ function __wbg_get_imports() {
const ret = false;
return ret;
};
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
const ret = getObject(arg0);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
const obj = getObject(arg1);
const ret = typeof(obj) === 'string' ? obj : undefined;
Expand Down Expand Up @@ -1636,28 +1636,28 @@ function __wbg_get_imports() {
const ret = wasm.memory;
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper818 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 197, __wbg_adapter_28);
imports.wbg.__wbindgen_closure_wrapper732 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 138, __wbg_adapter_28);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper985 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 238, __wbg_adapter_31);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper1533 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 436, __wbg_adapter_34);
imports.wbg.__wbindgen_closure_wrapper1545 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 448, __wbg_adapter_34);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper1535 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 436, __wbg_adapter_37);
imports.wbg.__wbindgen_closure_wrapper1547 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 448, __wbg_adapter_37);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper1537 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 436, __wbg_adapter_37);
imports.wbg.__wbindgen_closure_wrapper1549 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 448, __wbg_adapter_37);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper1915 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 463, __wbg_adapter_42);
imports.wbg.__wbindgen_closure_wrapper1927 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 475, __wbg_adapter_42);
return addHeapObject(ret);
};

Expand Down
Binary file modified web/json-editor_bg.wasm
Binary file not shown.

0 comments on commit 5f67116

Please sign in to comment.