0

I have a JSON like below, and have JSONPath like for example,

"$[0].child_members[7].diamond.diamond_id" => Line number 55
"$[1].match_departments[0]" => Line number 83

I want to find the line number for JSONPath in corresponding JSON. I am using Jackson and JayWayPath Libraries, but not able to figure out, is there a way possible to find line number based on JSONPath. If any one can suggest some idea, help is appreciated. Thanks.

[
    {
        "facility": "Global",
        "group_names": [
            "H R"
        ],
        "group_type": "department",
        "remove_users_on_logout": false,
        "shift_membership": {
            "min": 50,
            "max": 50,
            "source": "any_shift",
            "type": [
                "auxiliary"
            ]
        },
        "child_members": [
            {
                "diamond": {
                    "diamond_id": "akron_hr"
                }
            },
            {
                "diamond": {
                    "diamond_id": "baltimore_hr"
                }
            },
            {
                "diamond": {
                    "diamond_id": "charlotte_hr"
                }
            },
            {
                "diamond": {
                    "diamond_id": "dallas_hr"
                }
            },
            {
                "diamond": {
                    "diamond_id": "elpaso_hr"
                }
            },
            {
                "diamond": {
                    "diamond_id": "houston_hr"
                }
            },
            {
                "diamond": {
                    "diamond_id": "greensboro_hr"
                }
            },
            {
                "diamond": {
                    "diamond_id": "houston_hr"
                }
            },
            {
                "diamond": {
                    "diamond_id": "knoxville_hr"
                }
            },
            {
                "diamond": {
                    "diamond_id": "lakewood_hr"
                }
            },
            {
                "diamond": {
                    "diamond_id": "madison_hr"
                }
            },
            {
                "diamond": {
                    "diamond_id": "nashville_hr"
                }
            }
        ]
    },
    {
        "facility": "Akron",
        "match_departments": [
            "L T C",
            "M I C U"
        ],
        "child_members": [
            {
                "group_names": [
                    "Unit Alert"
                ],
                "group_type": "ordinary",
                "group_use": [
                    "unit_alert"
                ],
                "remove_users_on_logout": false,
                "name_format": "$department $name",
                "shift_membership": {
                    "min": 12,
                    "max": 12,
                    "source": "per_shift",
                    "type": [
                        "clinician"
                    ]
                }
            }
        ]
    }
]
Ankit Ostwal
  • 1,033
  • 3
  • 14
  • 32

1 Answers1

0

Whitespace is allowed and ignored around or between syntactic elements (values and punctuation, but not within a string value). Four specific characters are considered whitespace for this purpose: space, horizontal tab, line feed, and carriage return.

Source on Wikipedia

It will not be possible to produce exact line number because of the above, because adding some whitespace carriage return of line feed characters will change the line number, but not the JSON message.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Luuk
  • 12,245
  • 5
  • 22
  • 33
  • Hi @Luuk, i can make sure, my json is pretty json and well formatted. Its a pre-condition. Is it then possible? If you can guide me the approach. Or what do you think can be best to show to user, in this case, this particular entry has logical error (Syntactically it is correct), so that his/her life can be made easier. AS the actual file is around 12k-13k lines. Thanks. – Ankit Ostwal Aug 31 '21 at 06:19
  • You can try: https://github.com/maxsivanov/json-line-number – Luuk Aug 31 '21 at 06:20
  • I was looking for a JAVA based solution. Although thanks for the suggestion, i will take a look, to see logic. Thanks for your time. – Ankit Ostwal Aug 31 '21 at 06:29