nlohmann / nlohmann/json

msgpack parser failed to parse null as Map key

Open
#3,381 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

aspect: binary formats kind: bug state: please discuss
Dominant language
C++
Stars
50.6k
Forks
7.5k
Avg merge
4d 17h
Merged PRs (30d)
58

Description

What is the issue you have?

I'm trying to parse msgpack data like:

{
    null: 1
}

which serializes as 81 C0 01. But nlohmann::json::from_msgpack failed to parse it with

[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing MessagePack string: expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0xC0
Please describe the steps to reproduce the issue.

Can you provide a small but working code example?
#include <nlohmann/json.hpp>
int main() {
    const uint8_t src[] = {0x81, 0xC0, 0x01};
    nlohmann::json j = nlohmann::json::from_msgpack(src);
}
What is the expected behavior?

From the msgpack specs it doesn't restricts which value could be used on Map keys

And what is the actual behavior instead?

The specs above says

applications may remove Binary type, restrict keys of map objects to be String type, and put some restrictions to make the semantics compatible with JSON

So maybe it could be serialized to

{
    "null": 1
}

like other implementation does

Which compiler and operating system are you using?
  • Compiler: MSVC 19.30.30705
  • Operating system: Windows 11 22000.527
    Also reproduced on gcc11
Which version of the library did you use?
  • latest release version 3.10.5
  • other release - please state the version: 3.10.4
  • the develop branch
If you experience a compilation error: can you compile and run the unit tests?
  • yes
  • no - please copy/paste the error message below
  • N/A

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 at the nlohmann::json::from_msgpack entry point and reproduce the issue with the byte sequence 81 C0 01 from the report. Clarify whether null map keys should be accepted or converted for JSON compatibility, then add coverage for the agreed behavior and run the relevant unit tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend-api-design
Issue type
Bug
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.