Giter Site home page Giter Site logo

Parsing numbers about jc HOT 13 CLOSED

kellyjonbrazil avatar kellyjonbrazil commented on May 13, 2024
Parsing numbers

from jc.

Comments (13)

kellyjonbrazil avatar kellyjonbrazil commented on May 13, 2024 1

from jc.

ilyash-b avatar ilyash-b commented on May 13, 2024

would eliminate |tonumber in jq I guess

From readme:

ls -l /usr/bin | jc --ls | jq '.[] | select(.size|tonumber > 50000000)'

from jc.

kellyjonbrazil avatar kellyjonbrazil commented on May 13, 2024

from jc.

ilyash-b avatar ilyash-b commented on May 13, 2024

Suggested alternative: have a "schema" and now where the numbers supposed to be. If the user chooses -h for "human" output and then uses jc for machine parse-able that's an error (exception).

from jc.

ilyash-b avatar ilyash-b commented on May 13, 2024

I was thinking about stricter behaviour: you know where the numbers need to be. If the input is not a number, it's probably because of -h and jc probably should not parse anything like that because it's kind of sabotage by the user: runs the command explicitly requesting human output and makes jc parse it

from jc.

kellyjonbrazil avatar kellyjonbrazil commented on May 13, 2024

I think i'd like to keep the original representation, too, for other use cases. Since it's easy to add fields to json that can be ignored if not needed I don't mind making extra _num_x or whatever fields to convert known numbers to number format if they are parsable.

from jc.

kellyjonbrazil avatar kellyjonbrazil commented on May 13, 2024

Or actually, the opposite way so you can use the results more easily in your application.

Be strict in parsing, but if -h type of input is found and not parsable as a number, add a _fieldname with the non-parsable text output and you can just ignore the _fieldname fields if you just care about machine parsable data?

from jc.

kellyjonbrazil avatar kellyjonbrazil commented on May 13, 2024

Was thinking about this a bit more and I think it makes more sense to provide the existing output when the user passes a -r or raw=true flag. The default output would be a strict schema representation with additional semantic information.

This allows for both use cases where you can use jc as a layer higher than sed/awk/grep but can also use it for higher level presentation.

I’ll start working on this. This solves the conflict I ran into in the earlier versions and I think it will be good for your project.

from jc.

ilyash-b avatar ilyash-b commented on May 13, 2024

The default output would be a strict schema representation with additional semantic information.

Sounds good!

from jc.

kellyjonbrazil avatar kellyjonbrazil commented on May 13, 2024

Hi Ilya,

I have incorporated your suggestions into the dev branch. I'm still working on some fixes and documentation, but it's pretty close to being merged in the next week or two.

Feel free to test/provide feedback on the dev branch:

pip3 uninstall jc
git clone --single-branch --branch dev https://github.com/kellyjonbrazil/jc.git
cd jc
./install.sh

from jc.

ilyash-b avatar ilyash-b commented on May 13, 2024

Hi. Not getting to it. I'll take a look later.

from jc.

kellyjonbrazil avatar kellyjonbrazil commented on May 13, 2024

updates in master version 1.5.1, also via pip3

from jc.

kellyjonbrazil avatar kellyjonbrazil commented on May 13, 2024

from jc.

Related Issues (20)

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.