Open ccchan234 opened 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.
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:
# 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:
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.
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
hi, suppose i got a data.md file, which contains the json block
then, gpt4 suggested dv.md and dv2.md for me, but both failed when i "preview" them: dv.md:
dv2.md:
table myData
"Mindmap Data"
dv(```json
${read("data.md").match(/``` json\n([\s\S]+?)\n```/)[1]}
```).mindData
table myData
"Mindmap Data"
dv(```json
${read("data.md").match(/``` json\n([\s\S]+?)\n```/)[1]}
```)[0].mindData
help appreciated thx
data.md itself:
mindmap-plugin: rich
{"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":[]}
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
dataview can see the out-side-json line say hereditary::autosomal-recessive, dataview cant see the hereditary::x-linked etc inside json
DQL
`
JS
No response
Dataview Version
0.5.52
Obsidian Version
1.2.8
OS
Windows