Hierarchical data (was: Light weight support for JSON)

2022-09-01 Thread Chris Dunlop
On Wed, Aug 31, 2022 at 11:11:26AM -0400, Chet Ramey wrote: On 8/29/22 2:03 PM, tetsu...@scope-eye.net wrote: It would also help greatly if the shell could internally handle hierarchical data in variables. That's a fundamental change. There would have to be a better reason to make it than han

Re: Light weight support for JSON

2022-08-31 Thread George Caswell
On Wed, 2022-08-31 at 11:11 -0400, Chet Ramey wrote: > On 8/29/22 2:03 PM, tetsu...@scope-eye.net wrote: > > > It would also help > > greatly if the shell could internally handle hierarchical data in > > variables. > > That's a fundamental change. There would have to be a better reason > to make

Re: Light weight support for JSON

2022-08-31 Thread Robert E. Griffith
I am on vacation and just skimmed this long thread so I might have missed some of the context but I wanted throw out that I recently wrote a loadable plugin that among other things, can convert JSON to and from bash arrays. Anyone interested can check it out at these git repos. https://github

Re: Light weight support for JSON

2022-08-31 Thread Chet Ramey
On 8/29/22 2:03 PM, tetsu...@scope-eye.net wrote: On 2022-08-29 11:43, Chet Ramey wrote: On 8/28/22 2:11 PM, Lawrence Velázquez wrote: On Sun, Aug 28, 2022, at 9:24 AM, Yair Lenga wrote: Wanted to get feedback about the following "extensions" to bash that will make it easier to work with simpl

Re: Light weight support for JSON

2022-08-30 Thread Dale R. Worley
Greg Wooledge writes: > The standard idiom for this sort of thing is > > eval "$(external-tool)" > > This means you need to *trust* the external-tool to produce safe code. True. And I use that idiom with ssh-agent routinely. But it still strikes me as unnatural. Dale

Re: Light weight support for JSON

2022-08-29 Thread tetsujin
On 2022-08-29 11:43, Chet Ramey wrote: On 8/28/22 2:11 PM, Lawrence Velázquez wrote: On Sun, Aug 28, 2022, at 9:24 AM, Yair Lenga wrote: Wanted to get feedback about the following "extensions" to bash that will make it easier to work with simple JSON object. (...) just to make it easier to bu

Re: Light weight support for JSON

2022-08-29 Thread Chet Ramey
On 8/28/22 2:11 PM, Lawrence Velázquez wrote: On Sun, Aug 28, 2022, at 9:24 AM, Yair Lenga wrote: Wanted to get feedback about the following "extensions" to bash that will make it easier to work with simple JSON object. To emphasize, the goal is NOT to "compete" with Python/Javascript (and other

Re: Light weight support for JSON

2022-08-29 Thread Chet Ramey
On 8/28/22 5:50 PM, Yair Lenga wrote: First, thanks for taking the time to read and provide your thoughts. This is the real value of the discussion/ Second: I'm NOT trying to argue that there isn't valid use for combining bash/curl/jq, Nor do I suggest adding JSON as first class object to bash (

Re: Light weight support for JSON

2022-08-29 Thread Chet Ramey
On 8/28/22 8:47 PM, Dale R. Worley wrote: The "obvious" way to support Json in Bash would be a utility that parses Json and produces e.g. a Bash associative array, and conversely a utility that reads a Bash associative array and produces Json. The real limitation is that it's difficult to have a

Re: Light weight support for JSON

2022-08-29 Thread Chet Ramey
On 8/28/22 5:06 PM, Saint Michael wrote: He has a point, though. To have some of the functionality of jq inside Bash may be very useful. If he can supply a patch, why not? Because then it becomes a support and maintenance issue, and a piece of technical debt. A well-encapsulated loadable built

Re: Looking to the future (was Re: Light weight support for JSON)

2022-08-28 Thread Oğuz İsmail Uysal
On 8/29/22 5:48 AM, Martin D Kealey wrote: The Shell persists because it has one killer feature: it does double duty as a scripting language and as an interactive command language. But we're kidding ourselves if we think that no other language could fill that gap: Python has a respectable interac

Looking to the future (was Re: Light weight support for JSON)

2022-08-28 Thread Martin D Kealey
Not that I fundamentally disagree with this (JSON) proposal, but I'd rather see the effort put into support for nested arrays (like ksh has), and generally having a more forward-looking view of Bash as an evolving language. I would see this proceeding somewhat like the transition from Perl4 to Per

Re: Light weight support for JSON

2022-08-28 Thread Greg Wooledge
On Sun, Aug 28, 2022 at 08:47:24PM -0400, Dale R. Worley wrote: > The "obvious" way to support Json in Bash would be a utility that parses > Json and produces e.g. a Bash associative array, and conversely a > utility that reads a Bash associative array and produces Json. The real > limitation is t

Re: Light weight support for JSON

2022-08-28 Thread Dennis Williamson
On Sun, Aug 28, 2022 at 7:47 PM Dale R. Worley wrote: > The "obvious" way to support Json in Bash would be a utility that parses > Json and produces e.g. a Bash associative array, and conversely a > utility that reads a Bash associative array and produces Json. The real > limitation is that it's

Re: Light weight support for JSON

2022-08-28 Thread Dale R. Worley
The "obvious" way to support Json in Bash would be a utility that parses Json and produces e.g. a Bash associative array, and conversely a utility that reads a Bash associative array and produces Json. The real limitation is that it's difficult to have a subprocess set Bash's variables. As far as

Re: Light weight support for JSON

2022-08-28 Thread Yair Lenga
First, thanks for taking the time to read and provide your thoughts. This is the real value of the discussion/ Second: I'm NOT trying to argue that there isn't valid use for combining bash/curl/jq, Nor do I suggest adding JSON as first class object to bash (Python/node/Perl/Groovy are way ahead .

Re: Light weight support for JSON

2022-08-28 Thread Saint Michael
He has a point, though. To have some of the functionality of jq inside Bash may be very useful. If he can supply a patch, why not? Philip Orleans On Sun, Aug 28, 2022, 3:22 PM John Passaro wrote: > interfacing with an external tool absolutely seems like the correct answer > to me. a fact worth m

Re: Light weight support for JSON

2022-08-28 Thread Lawrence Velázquez
On Sun, Aug 28, 2022, at 9:24 AM, Yair Lenga wrote: > Wanted to get feedback about the following "extensions" to bash that will > make it easier to work with simple JSON object. It occurred to me to provide references for previous discussion along these lines, but it turns out there isn't very muc

Re: Light weight support for JSON

2022-08-28 Thread Lawrence Velázquez
On Sun, Aug 28, 2022, at 4:05 PM, G. Branden Robinson wrote: > At 2022-08-28T15:52:55-0400, Lawrence Velázquez wrote: >> On Sun, Aug 28, 2022, at 2:56 PM, G. Branden Robinson wrote: >> > How about next July, when JSON is as exactly old as the Bourne shell >> > was when JSON was deployed? >> >> I d

Re: Light weight support for JSON

2022-08-28 Thread G. Branden Robinson
At 2022-08-28T15:52:55-0400, Lawrence Velázquez wrote: > On Sun, Aug 28, 2022, at 2:56 PM, G. Branden Robinson wrote: > > How about next July, when JSON is as exactly old as the Bourne shell > > was when JSON was deployed? > > I do not find "well *actually* JSON is old too!!!" to be particularly >

Re: Light weight support for JSON

2022-08-28 Thread Lawrence Velázquez
On Sun, Aug 28, 2022, at 2:56 PM, G. Branden Robinson wrote: > At 2022-08-28T14:11:25-0400, Lawrence Velázquez wrote: >> I do not think bash needs to sprout functionality to support every >> data-exchange format of the month. > > This sentiment is illustrative of the logarithmic memory scale of > g

Re: Light weight support for JSON

2022-08-28 Thread John Passaro
interfacing with an external tool absolutely seems like the correct answer to me. a fact worth mentioning to back that up is that `jq` exists. billed as a sed/awk for json, it fills all the functions you'd expect such an external tool to have and many many more. interfacing from curl to jq to bash

Re: Light weight support for JSON

2022-08-28 Thread G. Branden Robinson
At 2022-08-28T14:11:25-0400, Lawrence Velázquez wrote: > I do not think bash needs to sprout functionality to support every > data-exchange format of the month. This sentiment is illustrative of the logarithmic memory scale of grognards. The Bourne shell was first released as part of Version 7 Un

Re: Light weight support for JSON

2022-08-28 Thread Lawrence Velázquez
On Sun, Aug 28, 2022, at 2:29 PM, Yair Lenga wrote: > I do not think that JSON (and REST) are "data exchange format of the > month". Those are established formats that are here to stay. Like YAML. > Those are "cornerstones" of cloud computing/configuration. I do not have to > argue for them, they c

Re: Light weight support for JSON

2022-08-28 Thread Yair Lenga
I do not think that JSON (and REST) are "data exchange format of the month". Those are established formats that are here to stay. Like YAML. Those are "cornerstones" of cloud computing/configuration. I do not have to argue for them, they can speak for themselves. As for using external utilities: t

Re: Light weight support for JSON

2022-08-28 Thread Lawrence Velázquez
On Sun, Aug 28, 2022, at 9:24 AM, Yair Lenga wrote: > Wanted to get feedback about the following "extensions" to bash that will > make it easier to work with simple JSON object. To emphasize, the goal is > NOT to "compete" with Python/Javascript (and other full scale language) - > just to make it e

Re: Light weight support for JSON

2022-08-28 Thread Yair Lenga
Interesting point. Using (optional) separate array can also address the problem of "types" - knowing which values are quoted, and which one are not. This can also provide enough metadata to convert modified associative table back to JSON. On Sun, Aug 28, 2022 at 9:51 AM Alex fxmbsw7 Ratchev wrote

Re: Light weight support for JSON

2022-08-28 Thread Alex fxmbsw7 Ratchev
On Sun, Aug 28, 2022, 15:46 Yair Lenga wrote: > Sorry for not being clear. I'm looking for feedback. The solution that I > have is using python to read the JSON, and generate the commands to build > the associative array. Will have to rewrite in "C"/submit if there is > positive feedback from oth

Re: Light weight support for JSON

2022-08-28 Thread Yair Lenga
Sorry for not being clear. I'm looking for feedback. The solution that I have is using python to read the JSON, and generate the commands to build the associative array. Will have to rewrite in "C"/submit if there is positive feedback from others readers. Yair. On Sun, Aug 28, 2022 at 9:42 AM Alex

Re: Light weight support for JSON

2022-08-28 Thread Alex fxmbsw7 Ratchev
On Sun, Aug 28, 2022, 15:25 Yair Lenga wrote: > Hi, > > Over the last few years, JSON data becomes a integral part of processing. > In many cases, I find myself having to automate tasks that require > inspection of JSON response, and in few cases, construction of JSON. So > far, I've taken one of

Light weight support for JSON

2022-08-28 Thread Yair Lenga
Hi, Over the last few years, JSON data becomes a integral part of processing. In many cases, I find myself having to automate tasks that require inspection of JSON response, and in few cases, construction of JSON. So far, I've taken one of two approaches: * For simple parsing, using 'jq' to extrac