open-source-parsers / open-source-parsers/jsoncpp

No way to get location of string key in a parsed file

Open
#1,283 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C++
Stars
8.9k
Forks
2.7k
Avg merge
31m
Merged PRs (30d)
1

Description

Is your feature request related to a problem? Please describe.
I would like to be able to determine exactly where in a file a string key in an object came from, so that I can emit useful error messages related to the contents of the key itself (not the value associated with it).

Describe the solution you'd like
I would like to add four new member functions to Json::Value:

  void setKeyOffsetStart(const char* begin, const char* end, ptrdiff_t start);
  void setKeyOffsetLimit(const char* begin, const char* end, ptrdiff_t limit);
  ptrdiff_t getKeyOffsetStart(const char* begin, const char* end) const;
  ptrdiff_t getKeyOffsetLimit(const char* begin, const char* end) const;

These are based on, and functionally similar to, setOffsetStart(), setOffsetLimit(), getOffsetStart(), and getOffsetLimit().

Describe alternatives you've considered
I could use getOffsetStart() and getOffsetLimit() to get the location of the value associated with the key, which would at least put the user in the vicinity of the key that they need to inspect. However, getting the location of the key itself (in case it's on a different line than the value) would be more ideal.

Additional context
I am trying to make some of CMake's error messages regarding errors in JSON files more detailed and helpful, but am running into limits from jsoncpp.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the existing setOffsetStart(), setOffsetLimit(), getOffsetStart(), and getOffsetLimit() implementations on Json::Value, then trace how parsed object keys are handled. Done means Json::Value provides the four requested key-offset functions and they report the key's location rather than the associated value's location.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.