Skip to content

Serializing json instances containing already serialized string values without escaping #385

Closed
@orcun

Description

I found it quite difficult to correctly describe my intention in the title, which is probably wrong. A picture is worth a thousand words, how much a code sample is worth?

// a user defined string literal _json_inlined, shorthand for json::make_inlined("") static function
json j = {"foo", 1, 2, 3, false, {{"one", 1}}, "{\"two\":2}"_json_inlined};
CHECK(j.dump() == "[\"foo\",1,2,3,false,{\"one\":1},{\"two\":2}]");

This enables passing json strings from a business logic layer to network layer without having to parse it. Please note that passing json instances may not be an option because of module boundaries. Opposite of this scenario (not fully parsing part of a json string) would also be great but seems very difficult without making big changes.

I have a working implementation which was quite straightforward and around 20 lines of code. However it requires definition of a new value type, so I wasn't able to design it as an extension. So my question is, do you think would allowing such extensions (perhaps using some template meta-programming techniques) is feasible? If so, perhaps I can help with that and implement this as an extension. If not, would you consider a pull request for just this capability? Or perhaps both 🐱

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions