bew / dotfiles

All my dotfiles in one place!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Have a kind of json-editor-mode

bew opened this issue · comments

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)

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": "mail@tomnomnom.com",
        "name": "Tom Hudson"
      }
    }
  }
]

To:

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

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)