dotfiles icon indicating copy to clipboard operation
dotfiles copied to clipboard

Have a kind of json-editor-mode

Open bew opened this issue 4 years ago • 2 comments

Depends on #96, for easy impl of:

  • context of cursor in doc
  • text objects for object/field/key/value/list

Motivations:

  • Write foo bar: in a new field like in an object, should expand to "foo bar": (with undo support?)

  • Add/Delete-a-line can auto-add/remove the trailing , at the end of previous json-item, if we're adding a line after the last item of an object or a list.

  • text objects for: (lowercase uses char-wise selection, uppercase version is line-wise)

    • o : object, io : in object
    • f : obj field / list item, if : in obj field / list item (if: not including the trailing ,) (OR j : json item and ij : in json item ? it's more generic)
    • l : list, il : in list
    • k : obj field key, ik : in obj field key (ik: inside quotes)
    • v : obj field value, iv : in obj field value (iv: inside quotes) (FIXME: also valid when value is a list/object?)

    OR: text objects like o, f/i, l, k, v with prefix ij & oj (for inner json X or outer json X)

bew avatar Jun 16 '21 22:06 bew

When I'm somewhere in a JSON, I want to know where I am (like a breadcrumb).

For example, show in a floating window just under(/above? or in vim's cmdline?) the current line: Currently in: json.paths["/folders/{id}"].put.requestBody.content["application/json"].schema

EDIT: treesitter should help greatly for this!


There's a great tool that allows to grep json easily, called gron: https://github.com/tomnomnom/gron which transforms:

[
  {
    "commit": {
      "author": {
        "date": "2016-07-02T10:51:21Z",
        "email": "[email protected]",
        "name": "Tom Hudson"
      }
    }
  }
]

To:

json[0].commit.author = {};
json[0].commit.author.date = "2016-07-02T10:51:21Z";
json[0].commit.author.email = "[email protected]";
json[0].commit.author.name = "Tom Hudson";

bew avatar Sep 15 '21 13:09 bew

Json schemas can give json validation, auto completion, etc... Big catalog of schemas at https://www.schemastore.org/

Available for neovim with https://github.com/b0o/schemastore.nvim (+ the json language server)

bew avatar Oct 17 '21 08:10 bew