You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/loading_data.md
+3-33Lines changed: 3 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,26 +6,7 @@ Earlier, we saw how you can use commands like [`ls`](/commands/docs/ls.md), [`ps
6
6
7
7
One of Nu's most powerful assets in working with data is the [`open`](/commands/docs/open.md) command. It is a multi-tool that can work with a number of different data formats. To see what this means, let's try opening a json file:
In a similar way to [`ls`](/commands/docs/ls.md), opening a file type that Nu understands will give us back something that is more than just text (or a stream of bytes). Here we open a "package.json" file from a JavaScript project. Nu can recognize the JSON text and parse it to a table of data.
31
12
@@ -213,13 +194,7 @@ version = "0.1.2"
213
194
214
195
The "Cargo.lock" file is actually a .toml file, but the file extension isn't .toml. That's okay, we can use the [`from`](/commands/docs/from.md) command using the `toml` subcommand:
215
196
216
-
```
217
-
> open Cargo.lock | from toml
218
-
──────────┬───────────────────
219
-
metadata │ [row 107 columns]
220
-
package │ [table 130 rows]
221
-
──────────┴───────────────────
222
-
```
197
+
@[code](@snippets/loading_data/cargo-toml.sh)
223
198
224
199
The [`from`](/commands/docs/from.md) command can be used for each of the structured data text formats that Nu can open and understand by passing it the supported format as a subcommand.
225
200
@@ -262,9 +237,4 @@ Or run any SQL query you like:
262
237
263
238
In addition to loading files from your filesystem, you can also load URLs by using the [`http get`](/commands/docs/fetch.md) command. This will fetch the contents of the URL from the internet and return it:
Currently, we track only the span of where values come from. Let's take a closer look at that:
30
30
31
31
```
32
-
> open Cargo.toml | metadata | get span
33
-
───────┬────
34
-
start │ 5
35
-
end │ 15
36
-
───────┴────
32
+
> metadata (open Cargo.toml) | get span
33
+
╭───────┬────────╮
34
+
│ start │ 212970 │
35
+
│ end │ 212987 │
36
+
╰───────┴────────╯
37
37
```
38
38
39
39
The span "start" and "end" here refer to where the underline will be in the line. If you count over 5, and then count up to 15, you'll see it lines up with the "Cargo.toml" filename. This is how the error we saw earlier knew what to underline.
0 commit comments