farling42 / obsidian-import-json

Plug-in for Obsidian.md which will create Notes from JSON files
MIT License
88 stars 5 forks source link

Can multiple values in one cell work? #7

Closed ooker777 closed 2 years ago

ooker777 commented 2 years ago

Say my CSV file is:

name,value
Alice,a
Bob, "b,c,d" 

And my template:

{{name}}:: [[{{value}}]] 

In Alice.md it returns Alice:: a as expected. But in Bob.md it returns Bob:: [[ "b]]. Is it possible to have it return like this?

Bob:: b
Bob:: c
Bob:: d
farling42 commented 2 years ago

Hi, because you have a space on the second line after the comma, it is reading the rest of the line as three more fields. If you had:

name,value
Alice,a
Bob,"b,c,d"

Then it would end up with:

Bob:: [[b,c,d]]

Unfortunately nesting of lists isn't really possible in CSV file formats, and I'm not sure how easy it would be to implement it locally. It would have to consider quotes within quotes and other special characters that could interrupt the detection of commas within the field.

ooker777 commented 2 years ago

I find the csv-to-md script work like a charm. Do you think it would be best to recommend using it to other users as well?

farling42 commented 2 years ago

I find the csv-to-md script work like a charm. Do you think it would be best to recommend using it to other users as well?

How do you use that script to break up your "b,c,d" single value?

ooker777 commented 2 years ago

not really (see this issue). But it can make it to

Bob:: [[b]] [[c]] [[d]] 

and from there you can use regex to split it into multiple lines

farling42 commented 2 years ago

If it is a list, then the handlebars #each can be used to iterate over the list to add some text multiple times. So your template could become:

{{#each value}} {{name}}:: {{this}} {{/each}}

It might be that name needs to be accessed as {{../name}} instead of just {{name}}

See https://handlebarsjs.com/guide/builtin-helpers.html#each