ijl / orjson

Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy
Apache License 2.0
6.06k stars 209 forks source link

I need 4 indent features. #512

Closed danerlt closed 3 weeks ago

danerlt commented 1 month ago

After reviewing the document, I found that it supports reducing indentation with 2 spaces. How can I format it to reduce indentation using 4 spaces?

I have the following Python test code, which works correctly.

def test_dumps_vs_stb_lib():
    data = {"name": "你好", "age": 20, "sex": "man"}
    std_json_str = json.dumps(data, ensure_ascii=False, indent=2)
    print(std_json_str)
    or_json_str = orjson.dumps(data, option=orjson.OPT_INDENT_2).decode("utf-8")
    print(or_json_str)
    assert std_json_str == or_json_str

I want to achieve an indentation of 4 spaces to make the following code test pass:

def test_dumps_vs_stb_lib_2():
    data = {"name": "你好", "age": 20, "sex": "man"}
    std_json_str = json.dumps(data, ensure_ascii=False, indent=4)
    print(std_json_str)
    or_json_str = orjson.dumps(data, option=orjson.OPT_INDENT_4).decode("utf-8")
    print(or_json_str)
    assert std_json_str == or_json_str