alexwennerberg / json2csv

Convert JSON to CSV in Rust
MIT License
16 stars 4 forks source link

json2csv doesn't work on arrays of objects #3

Open ehiggs opened 3 years ago

ehiggs commented 3 years ago

Given the following:

[
    {
        "name": "michael",
        "family": [
            {
                "name": "theodore",
                "relation": "father"
            }
        ]
    },
    {
        "name": "john",
        "family": [
            {
                "name": "jane",
                "relation": "sister"
            },
            {
                "name": "janet",
                "relation": "mother"
            }
        ]
    }
]
jslint test.json
(node:46179) Warning: Accessing non-existent property 'runMain' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)

test.json is OK.

Yields the following:

RUST_BACKTRACE=1 json2csv test.json                     
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /Users/ehiggs/.cargo/registry/src/github.com-1ecc6299db9ec823/json2csv-0.1.0/src/convert.rs:45:17
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: std::panicking::rust_panic_with_hook
   6: rust_begin_unwind
   7: core::panicking::panic_fmt
   8: core::panicking::panic
   9: json2csv::convert::write_json_to_csv
  10: json2csv::main
  11: std::rt::lang_start::{{closure}}
  12: std::rt::lang_start_internal
  13: main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
alexwennerberg commented 1 year ago

I should improve err handling in this library. This was the firs thing I ever wrote in rust

I need a streaming json parser in order to do this. I know there are a few options, but I haven't looked into them. TBD