Skip to content

Support for binary arrays #53

Description

@vlad-nn

NLohmann JSON version 3.10.4 has binary arrays: https://json.nlohmann.me/api/basic_json/binary/
If such array is encountered in JSON object, pyjson::from_json() crashes with stack overflow because it falls to "else // Object" clause and then the for() loop tries to iterate over non-existing values, since binary array is not an object.

Proposed fix:

  1. Add include file:
    #include "pybind11/numpy.h"

  2. In pyjson::from_json() add:
    ...
    else if (j.is_binary())
    {
    const auto &bin = j.get_binary();
    return py::array( bin.size(), bin.data() );
    }
    else // Object
    {
    ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions