blacksmithgu / obsidian-dataview

A data index and query language over Markdown files, for https://obsidian.md/.
https://blacksmithgu.github.io/obsidian-dataview/
MIT License
6.94k stars 411 forks source link

dataview didn't scan the markdown file wholely, #1921

Open ccchan234 opened 1 year ago

ccchan234 commented 1 year ago

What happened?

i use another plugin called markmind, the phase: autosomal-recessive is embedded in a json paragraph. dataview didn't scan inside the json paragraph.

as see in this: https://github.com/MarkMindCkm/obsidian-markmind/issues/679

the whole file is like: ` mindmap-plugin: rich

tags: dv-test


hereditary::autosomal-recessive

mindmap-plugin: basic

{"theme":"","mindData":[[{"id":"3c7689f1-ae41-a570","text":"mindmap-plugin: basic","isExpand":true,"useHandMode":false,"isRoot":true,"useScale":true,"x":3940,"y":3800,"main":true,"layout":{"layoutName":"mindmap2","direct":"mindmap"},"stroke":""},{"id":"75cd1f0d-f89e-dd49","text":"hello","stroke":"#c6a5e5","x":4282,"y":3810,"layout":null,"isExpand":true,"pid":"3c7689f1-ae41-a570"},{"id":"54716d2d-153a-901c","text":"hereditary::x-linked","stroke":"#c6a5e5","x":4372,"y":3800.5,"layout":null,"isExpand":true,"pid":"75cd1f0d-f89e-dd49"},{"id":"56a83998-c937-8011","text":"hereditary::autosomal-dominant","stroke":"#c6a5e5","x":4372,"y":3835.5,"layout":null,"isExpand":true,"pid":"75cd1f0d-f89e-dd49"}]],"induceData":[],"wireFrameData":[],"relateLinkData":[],"calloutData":[]}

dataview can see the out-side-json line say hereditary::autosomal-recessive, dataview cant see the hereditary::x-linked etc inside json

DQL

table hereditary
from #dv-test

`

JS

No response

Dataview Version

0.5.52

Obsidian Version

1.2.8

OS

Windows

AB1908 commented 1 year ago

This isn't a bug. Dataview doesn't parse JSON that way, mostly because there are few out there that write it this way. You may want to drop down into DVJS and parse it yourself.

ccchan234 commented 1 year ago

gpt4 suggest me to have a sidecar file, that contain the dv( ) to grab the data of that json, is that what you suggest to do? thanks

me: how to use obsidian's dataview's dataviewjs to parse a md file that contains a json block? gpt4:You can use Obsidian's Dataview plugin and its DataviewJS extension to parse a Markdown file that contains a JSON block.

Here's an example of how to do this:

  1. Create a Markdown file in your Obsidian vault that includes a JSON block. For example:
    
    # Example

This is an example note.

{
  "name": "John Doe",
  "age": 30,
  "city": "New York"
}

2. In a separate Markdown file, use the Dataview plugin and its `dv` code block to query the JSON data in the first file. For example:

title: JSON Query

table jsonData
"Name", "Age", "City"
dv(```json
${read("Example.md").match(/```json\n([\s\S]+?)\n```/)[1]}
````).name, dv(```json
${read("Example.md").match(/```json\n([\s\S]+?)\n```/)[1]}
```").age, dv(```json
${read("Example.md").match(/```json\n([\s\S]+?)\n```/)[1]}
```").city


In this example, the `read()` function is used to read the contents of the "Example.md" file, and the `match()` function is used to extract the JSON block from the file. The extracted JSON block is then passed to the `dv()` function, which uses DataviewJS to query the JSON data and return the values of the "name", "age", and "city" properties as a table.

You can customize the query to match the structure and format of your JSON data and display the results in a format that suits your needs.

I hope this helps! Let me know if you have any further questions or if there's anything else I can assist you with.

me:what do you mean by parse? what it does?
gpt4:When I say "parse" in the context of using Dataview's DataviewJS to query a Markdown file that contains a JSON block, I mean extracting the JSON data from the Markdown file and converting it into a format that can be used for data analysis and manipulation. In other words, parsing means taking a raw input (in this case, a JSON block embedded in a Markdown file) and transforming it into a structured output that can be used for further processing.

In the example I provided, the DataviewJS code uses the `read()` function to read the contents of the Markdown file, and the `match()` function to extract the JSON block from the file. The extracted JSON block is then passed to the `dv()` function, which uses DataviewJS to query the JSON data and return the values of the "name", "age", and "city" properties as a table.

By parsing the JSON data in this way, you can use Dataview's powerful query and aggregation functions to analyze and manipulate the data in various ways, such as filtering, sorting, grouping, and calculating values based on the data.

I hope this helps clarify what I meant by "parse" in this context. Let me know if you have any further questions or if there's anything else I can assist you with.
ccchan234 commented 1 year ago

not easy to understand...

in usual days i got data.md(contain item::data, tagged) and than a dv.md (contain the dv query block)

now, suppose there is still a data.md, then a data2.md (contains json), and the dv.md i think have to make a data3.md and use dvjs to use read() the data2.md's json. but then how can dv.md also grab data3.md?

tag data3.md as tagging data.md?

thanks

ccchan234 commented 1 year ago

hi, suppose i got a data.md file, which contains the json block

image

then, gpt4 suggested dv.md and dv2.md for me, but both failed when i "preview" them: dv.md: image

dv2.md: image

ccchan234 commented 1 year ago

dv1.md:

title: My Dataview


table myData
"Mindmap Data"
dv(```json
${read("data.md").match(/``` json\n([\s\S]+?)\n```/)[1]}
```).mindData
ccchan234 commented 1 year ago

dv2.md:

title: My Dataview


table myData
"Mindmap Data"
dv(```json
${read("data.md").match(/``` json\n([\s\S]+?)\n```/)[1]}
```)[0].mindData
ccchan234 commented 1 year ago

help appreciated thx

ccchan234 commented 1 year ago

data.md itself:


mindmap-plugin: rich


mindmap-plugin: basic

{"theme":"","mindData":[[{"id":"d937766d-8ff7-6586","text":"mindmap-plugin: basic","isExpand":true,"useHandMode":false,"isRoot":true,"useScale":true,"x":3940,"y":3800,"main":true,"layout":{"layoutName":"mindmap2","direct":"mindmap"},"stroke":""}]],"induceData":[],"wireFrameData":[],"relateLinkData":[],"calloutData":[]}