-8

I've posted this question that has been closed with the reason:

This question needs to be more focused (...)

Update the question so it focuses on one problem only.

Why?

The question is focused on a JSON parsing problem. I believe I was misunderstood. I gave an example, and asked for help finding solution for a general case.

Could someone point me to what is out of focus in this question and help me fix it?

3
  • 3
    Most likely because you should pick a specific tool (python, jq, or Linux command-line generally - but note that general command-line usage questions are off-topic here). Questions that ask how to do something in any of multiple tools are not well-suited to the Stack Exchange format, which is best suited to one question per technology.
    – Ryan M Mod
    Commented Sep 7, 2022 at 2:27
  • I didn't know about this rule. It's weird for me. I am discussing exactly this subject here.
    – Berk7871
    Commented Sep 7, 2022 at 3:18
  • This seems highly similar: Are questions seeking answers in either of two or more languages on-topic? Commented Sep 7, 2022 at 14:17

2 Answers 2

11

Welcome to Stack Overflow.

Quoting from the question:

I would like to know if there an option in jq (or a Python library, or some other linux/command line utility) that, instead of printing the value itself, prints the location (line and column, start and end position) of the value within a (valid) JSON file, given an Object Identifier-Index (.key2.key2_2.key2_2_1 in the example).

In other words: "Can I get this result from jq? If so, how? Otherwise, can I do it with a different command-line utility? Can I do it with a Python library? If so, which one, and what code do I need to write in order to make that work?"

The "if so"s can be considered logical extensions, but there are still realistically three questions here. We expect one at a time. (Similarly: questions should normally only be tagged with one language; the exception is when you're inter-operating between code written in multiple languages - not when translating from one to another.) Further, trying to find the appropriate command (especially if it's not one that comes standard with the OS) or a third-party library is explicitly off-topic (although that's a separate close reason). (Yes, JSON parsing is built into the Python standard library, but it won't give you this information, at least not in any obvious or direct way.)

(Finally: it's a strange requirement. If parsing the data was successful, then why does it matter how much whitespace is in the file, or what the order of the keys is, or whatever other factors influence the line and column position of the searched-for data's representation in the original text? Line and column numbers are for debugging, when the file contents aren't valid JSON.)

13
  • 1
    My English may not have been good enough. I'll try to explain what I wrote: I asked for a solution using preferably JQ. If it is not possible to solve with JQ, I would consider some solution in python, and finally, if it is not possible with these two ways, it could be through another linux command line program. If I asked what the best way to filter through REGEX on the linux command line do I need to specify ONE tool I want? Couldn't it cover awk, sed, perl, etc? This site rule doesn't look quite right.
    – Berk7871
    Commented Sep 7, 2022 at 3:11
  • 1
    And about you finding this a strange requirement, I tell you that I'm developing a tool that patches a JSON file without changing its original formatting (because in this specific case, keeping the original formatting matters a lot). So I need to know the position of the value in the file. I didn't mention this in the question as I thought it wouldn't matter why I need the position.
    – Berk7871
    Commented Sep 7, 2022 at 3:14
  • 5
    "I'll try to explain what I wrote: I asked for a solution using preferably JQ. If it is not possible to solve with JQ, I would consider some solution in python, and finally, if it is not possible with these two ways, it could be through another linux command line program" I understood that perfectly. It is not appropriate to ask the question that way here, because Stack Overflow is not a discussion forum. You are expected to choose a general approach first, at least as far as what language or tool you are using. Commented Sep 7, 2022 at 3:25
  • 4
    I don't follow this logic. Why does the site inexorably become a discussion forum because the asker asks a how-to question without an inflexible constraint on what tool to use?
    – Cody Gray Mod
    Commented Sep 7, 2022 at 7:29
  • 5
    @CodyGray "How can I do it with X?" "X is not capable of the task." "Oh, well how can I do it with Y?" would be a discussion. Pre-emptively asking multiple versions is perhaps not discussion in the usual sense, but it indicates a general trend towards "I just want to figure out a way to solve my problem" and away from "this question and answer site is missing an important question". Commented Sep 7, 2022 at 7:35
  • 7
    You prefer that the user ask an endless stream of follow-up "well, how can I do it with Y?" questions? Someone wanting to figure out a way to solve a problem is a useful contribution to a Q&A site that aims to build a database of high-quality solutions to problems encountered by programmers. It seems that perhaps you think the question is too open-ended because it doesn't put enough constraints on the solution to the problem, but I think that's misguided. We don't want to pigeonhole users into asking X-Y questions. Nor should the least knowledgeable person attempt to pre-ordain the solution.
    – Cody Gray Mod
    Commented Sep 7, 2022 at 7:40
  • 2
    If only we were all on the same page eh? But you have people who rigidly try to apply rules in order to be able to close as much as possible (probably in a response to a huge influx of incoming material which keeps review queues permanently full) VS people who are, like in the golden years of less questions asked, out to keep as much open as possible by using the rules more as guidelines. Everyone has a valid point to make in that regard. Kind of maddening.
    – Gimby
    Commented Sep 7, 2022 at 8:52
  • 2
    @CodyGray What's wrong about having separate "How to do X?" per language? After all, re-using solutions usually goes along with using a specific language. To anyone looking for the solution to combine with their code in language Y, solutions in language Z are at best noise. Even with just two language candidates, that's about 50% noise already. Commented Sep 7, 2022 at 14:08
  • 1
    "You prefer that the user ask an endless stream of follow-up "well, how can I do it with Y?" questions?" As separate questions, tagged appropriately (so that I only have to see the ones relevant to technologies I'm interested in), asked in accordance with other site guidance? Absolutely. It realistically won't be endless, or even that long anyway. Commented Sep 7, 2022 at 19:18
  • "It seems that perhaps you think the question is too open-ended because it doesn't put enough constraints on the solution to the problem, but I think that's misguided." Questions that ask for a solution in either of two different programming languages are routinely closed nowadays. I don't see why asking for a solution in "either one programming language or one command-line tool or possibly a different tool I don't know about" is any better. This isn't like people asking to use regex where regex isn't appropriate. In those cases, scope is broadened to one language, not multiple approaches. Commented Sep 7, 2022 at 19:20
  • Put another way: if it were broadened to "how can I get my computer to give me this information about the JSON file that it's currently storing", that would actually regain "focus" as I understand the concept - but it would also be a question for superuser, not here. Commented Sep 7, 2022 at 19:23
  • Based on the scores of this question and the original one (-8 and -4 respectively), I must have done something very bad for suggesting some possible tools. I've seen other questions in SO with excellent answers that would fit this "out of focus" criterion. Anyway I already revised the original question saying that the problem must be solved exactly and precisely with the tool (jq), and now I'm waiting for the analysis and possible reopening. Living and learning.
    – Berk7871
    Commented Sep 8, 2022 at 3:20
  • 1
    Be aware that Meta is much more free with downvotes than the main site; here we hold ourselves free to use them to indicate simple disagreement, among other things. Commented Sep 8, 2022 at 3:21
1

I find the SO question perfectly on-topic and properly scoped (that is, not "too broad").

The question asks about a tool for parsing JSON which is able to provide specific information (location of the value in the JSON file). In on-topic list this falls into the category "software tools commonly used by programmers".

As for scoping, a simple request for a command line tool would be sufficient to make the question not broader than "how to extract <something> from a shared library" sort of questions, e.g. that one.

Original scoping

I would like to know if there an option in jq (or a phython library, or some other linux/command line utility)

could be viewed as "too broad" reason, because command line tools and Python libraries are definitely different areas which should be searched separately. But since other parts of the question don't note Python at all, I find it reasonable to assume that Python is not the main concern for the asker. At least, it could be clarified with a comment like

Command line tools and Python libraries represent separate areas for search, but it seems that Python is not your main concern, so it could be removed from your question.

The current scoping

I would like to know if there is an option in jq

seems to be too strict, but on a potential asker's side I would treat this as "any command line tool is applicable".


Some time ago I searched for a Python library which parsed YAML and stored locations of the values. Finally I decided to wrap pyyaml with my classes.

So I would expect that command line tools lack support for this too. But the comment from @pmf suggests that some ways exist on that road.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .