Giter Site home page Giter Site logo

Comments (12)

kellyjonbrazil avatar kellyjonbrazil commented on May 27, 2024

Could you try with the -r option? I thought I added the capability to retain the case of key names but that may have been another parser.

from jc.

zenoweed avatar zenoweed commented on May 27, 2024

Apparently not. Here is the output:

brian@aspire:~$ cat file.ini | jc --ini -p -r
{
  "something_key": "djhasjdhasdk",
  "something_else_key": "WBCKDJCBDS",
  "something_else_entirely_key": "4BH4J4dncdd"
}

from jc.

kellyjonbrazil avatar kellyjonbrazil commented on May 27, 2024

Thanks, I’ll take a closer look.

from jc.

kellyjonbrazil avatar kellyjonbrazil commented on May 27, 2024

Ah I see this is why it seemed familiar. I was able to preserve case in the kv parser, which also uses the configparser library like the INI parser does.

# don't convert keys to lower-case:

Don't want to change the default behavior, but I could either make it so -r also does not change case or just create a new INI parser that does this.

from jc.

zenoweed avatar zenoweed commented on May 27, 2024

Hi Kelly, so sorry for the delayed response. Well retaining cases with -r sounds good . But shouldn't retaining letter cases be the default behavior? As far as I know programming variables are always case sensitive. Does it help anyone when the key letter cases are converted to lowercase?

As in my case they are environment variables and will always have to be capitalized, for now as a go around I'm using jc and piping it to jq which capitalizes the keys for me:

cat repository/.${ENVIRONMENT}.ini | jc --ini -r -p | jq 'to_entries | map({(.key | ascii_upcase): .value}) | add' > .${ENVIRONMENT}.json

from jc.

kellyjonbrazil avatar kellyjonbrazil commented on May 27, 2024

I absolutely agree with you that it should be the default, but this would be a breaking change for anyone currently using the INI parser in their scripts. I could deprecate --ini and create --ini2 or something.

Unfortunately, I didn't realize the configparser library was doing that and there was a way to stop it in when I first developed the INI parser, so now it's been out there in production like this for a while.

I do have a way to deprecate parsers, so maybe I'll go that route. I'll have to think about a good way to do it here.

from jc.

kellyjonbrazil avatar kellyjonbrazil commented on May 27, 2024

What version of jc are you using? (jc -v)

This should already be working as expected since version 1.22.0.

from jc.

zenoweed avatar zenoweed commented on May 27, 2024

Hi Kelly,

So looks like mine is an older version. I had installed it using apt. I'm currently on ubuntu 22.04.3 LTS, Gnome 42.9 if that helps.

brian@aspire:~$ jc -v
jc version 1.17.3
https://github.com/kellyjonbrazil/jc
© 2019-2021 Kelly Brazil

from jc.

kellyjonbrazil avatar kellyjonbrazil commented on May 27, 2024

Ah yes, that makes sense. You can copy this ini.py file to you parser plugin directory to get the new behavior until you can upgrade jc:

https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/ini.py

  • Linux/unix: $HOME/.local/share/jc/jcparsers
  • macOS: $HOME/Library/Application Support/jc/jcparsers
  • Windows: $LOCALAPPDATA\jc\jc\jcparsers

from jc.

zenoweed avatar zenoweed commented on May 27, 2024

Thank you for this. But I was curious as to why I did not get the latest jc using apt. Neither did the ubuntu ec2 my company's Jenkins runs on.

from jc.

kellyjonbrazil avatar kellyjonbrazil commented on May 27, 2024

It looks like the package maintainers don't automatically upgrade the jc package on Ubuntu unless it is requested. Here is the latest information: https://repology.org/project/jc/versions

Instead of installing via OS package, you can also install via PIP or by downloading and running the precompiled binary.

from jc.

zenoweed avatar zenoweed commented on May 27, 2024

Ok. Thank you for this. The pip option sounds so much better.

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.