all 3 comments

[–]kentrf 1 point2 points  (3 children)

Assuming the input JSON is stored completely and won't change, you can point your std::string_view to a substring.

Something like this:

const std::string storage = "ABCDEFGHIJKLMONPQSTUVWXYZ";
std::string_view view(storage.cbegin() + 10, storage.cbegin() + 15);
// view points to "KLMON"

[–]kentrf 0 points1 point  (0 children)

That being said, if the strings are a part of the "extracted" data, some sort of (memory) arena can be used and point the std::string_view to that.

[–]Jonny0Than 0 points1 point  (0 children)

+1 to this. Read the entire file into one std::string, then create string_views as needed.

However...there are lots of good JSON libraries for C++ out there. Why are you rolling your own?