Scraps: json
2 items
This command, designed for macOS users, is a handy tool for extracting all unique paths (keys) from a…
**Summary of Command for Extracting JSON Paths**
• **Purpose**: This command, designed for macOS users, is a handy tool for extracting all unique paths (keys) from a large JSON file residing in the clipboard. It's particularly useful for data analysis, visualization design, and understanding the structure of complex JSON data without manual exploration.
• **Command Breakdown**:
- `pbpaste`: Pastes the content of the clipboard into the command line.
- `jq -c paths(scalars)`: Uses the `jq` command-line JSON processor to extract all paths (keys) from the JSON data. The `-c` option ensures compact output.
- `map(if type == number then [] else tostring end)`: Converts non-number types to strings, as `jq` treats numbers and strings differently.
- `join(.) | sort | uniq`: Joins the paths, sorts them, and removes duplicates to ensure a unique list of paths.
• **Usage**: Copy a large JSON file into your clipboard, then run this command in your terminal to quickly extract and display all unique paths (keys) in the JSON data.
• **Example Output**: If your JSON file contains the following structure:
```
{
"user": {
"name": "John",
"age": 30,
"address": {
"street": "123 Main St",
"city": "Anytown"
}
}
}
```
The command will output:
```
["address", "address.city", "address.street", "user", "user.address", "user.name"]
```
• **Use Cases**:
- Designing data views or visualizations by quickly understanding the JSON structure.
- Identifying available keys for filtering, aggregating, or transforming data.
- Debugging and troubleshooting JSON-related issues.
• **Author**: The command's author is unknown, but it's a popular tip shared among data professionals and developers for efficient JSON manipulation.
• **Context**: You saved this command because you frequently work with large JSON files and wanted a quick way to understand their structure and available keys for data analysis and visualization tasks.
mastodonpostdiscussionMay 24, 2024
shared
Conf: tags 68% summary 100%
jsoncanvas/assets/canvas.js at main · obsidianmd/jsoncanvas
**Summary of jsoncanvas/assets/canvas.js**
• **Purpose**: `canvas.js` is a JavaScript library developed by Obsidian MD for creating and manipulating JSON canvas data structures. It's designed to work with the JSON Canvas format, a simple and flexible way to represent interactive diagrams and graphs.
• **Key Features**:
- Supports creating, reading, and writing JSON canvas data.
- Allows manipulating canvas elements like nodes, edges, and ports.
- Provides utility functions for working with canvas data, such as serializing and deserializing JSON canvas data.
- Offers event handling for canvas changes.
• **How it Works**:
- The library exports a single `Canvas` class that represents a JSON canvas.
- Instances of this class can be initialized with an existing JSON canvas data or created empty.
- Methods like `addNode`, `addEdge`, `removeNode`, etc., allow adding, removing, and modifying elements in the canvas.
- The `serialize` and `deserialize` methods are used to convert canvas data to and from JSON strings.
• **API Details**:
- `new Canvas(data?: Object)`: Initializes a new `Canvas` instance with optional JSON canvas data.
- `canvas.serialize()`: Returns a JSON string representing the current state of the canvas.
- `canvas.deserialize(json: string)`: Updates the canvas with JSON canvas data from a string.
- `canvas.addNode(nodeData: Object)`: Adds a new node to the canvas.
- `canvas.removeNode(nodeId: string)`: Removes a node from the canvas by its ID.
- `canvas.addEdge(edgeData: Object)`: Adds a new edge to the canvas.
- `canvas.on('change', callback)`: Registers a callback function to be invoked when the canvas changes.
• **Examples**:
- Initializing an empty canvas: `const canvas = new Canvas();`
- Adding a node: `canvas.addNode({ id: 'n1', label: 'Node 1' });`
- Adding an edge: `canvas.addEdge({ source: 'n1', target: 'n2' });`
• **Limitations**:
- The library only supports JSON canvas data structures and doesn't provide visualization or rendering functionality.
- It doesn't handle canvas layout or positioning of elements.
• **Why this was saved**: This library was saved because it's a useful tool for working with JSON canvas data in JavaScript projects. It simplifies creating, manipulating, and serializing JSON canvas data, making it easier to work with interactive diagrams and graphs in web applications.
• **Context**: This library is part of the Obsidian MD project, which aims to create a powerful and extensible knowledge base and note-taking tool. JSON canvas is used to represent interactive diagrams within Obsidian MD, and `canvas.js` is the JavaScript library that enables working with this data format.