Skip to content

json::parse(begin, end) parse error on first character using uchar* #1887

Description

@johannes-do

What is the issue you have?

Using the json::parse() function with uchar* yields in a parsing error for the very first character.

Please describe the steps to reproduce the issue.

// outImg is of type cv::Mat (with outImg.rows > 0 and outImg.cols > 0)
uchar* imgBuff = outImg.isContinuous() ? outImg.data : outImg.clone().data;
size_t imgBuffSize = outImg.rows * outImg.cols * outImg.channels();
auto rawImgStr = nlohmann::json::parse(imgBuff, imgBuff + imgBuffSize);

What is the expected behavior?

A parsed img string can be added to the json object such as:

nlohmann::json output = {
  {"image", rawImgStr},
  {"imgWidth", outImg.size().width},
  {"imgHeight", outImg.size().height},
};

std::vector<std::uint8_t> v_bson = json::to_bson(output);

And what is the actual behavior instead?

Getting this error:

[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: 'D'

Which compiler and operating system are you using?

GCC v7.4, Linux Mint 19

Did you use a released version of the library or the version from the develop branch?

Release version: 3.7.3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions