GithubHelp home page GithubHelp logo

icyflame / json-where Goto Github PK

View Code? Open in Web Editor NEW
0.0 4.0 0.0 426 KB

Where are you inside a JSON file?

License: Other

Makefile 0.55% C++ 97.29% Shell 0.37% M4 1.80%
json json-path editor-plugin vim-plugin

json-where's Introduction

json-where

Where are you inside a JSON file?

asciicast

Note: I place the cursor on various keys in the JSON file and then type the mapping <leader>jw, which invokes the JsonWhere() vim function, which in turn invokes the json-where executable. You can look at the bottom left corner of the video to see the JSON path being printed to the screen.

Contents

Usage

json-where can be used from the command line. You can also set it up to run using a keybinding inside the editor of your choice.

Command line

# json-where file-name line column
$ json-where test.json 250  14
.[5].tags[3]

Vim

After installing json-where, you can use this function to invoke it based on your cursor position from within vim.

function JsonWhere()
    if executable("json-where") == 0
        return 'ERROR: json-where not found'
    endif

    let cursor = getcurpos()
    let lnum = cursor[1]
    let colnum = cursor[2]

    let filename = expand('%:p')
    if len(filename) == 0
        let filename = tempname() + ".json"
        silent exe("write! " . filename)
        silent exe("edit " . filename)
    endif

    let cmd_list = [ ]
    let cmd_list += [ 'json-where' ]
    let cmd_list += [ filename ]
    let cmd_list += [ lnum ]
    let cmd_list += [ colnum ]

    let cmd = join(cmd_list, ' ')
    let json_where_output = systemlist(cmd)

    if len(json_where_output) > 0
        return json_where_output[len(json_where_output)-1]
    else
        return 'ERROR: json-where output is invalid'
    endif
endfunction

You can attach a keybinding to this function in normal mode:

nmap <leader>jw :echo JsonWhere()<cr>

Note: For best results, call JsonWhere with the cursor on the first character in the JSON key or value.

Compile from source

json-where is a C++11 program. It can be compiled and installed using the standard GNU program compile process:

$ ./configure
$ make
$ sudo make install

When this repository is cloned, the configure script will be missing. You can create it by running the autogen.sh script.

By default, these commands will install the executable json-where inside /usr/local/bin/. You can change the destination by running the configure script with the --prefix option. Other options that you can pass to the configure script can be found on the autoconf manual.

Credits

TODO

  • Move the Vim function in this readme to it's own Vim plugin
  • Man page

License

minijson_reader's LICENSE is included here and appended to the LICENSE notice at the root of this repository.

Everything else in this repository is licensed under the MIT license.

Copyright (C) 2019 Siddharth Kannan [email protected]

json-where's People

Contributors

icyflame avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.