File size: 571 Bytes
6ff22d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import json

class NoIndent:
    """ Wrapper class to mark lists that should not be indented """
    def __init__(self, value):
        self.value = value

class CustomEncoder(json.JSONEncoder):
    """
    Custom JSON encoder that handles the NoIndent class to produce
    a compact string representation of the list
    """
    def default(self, obj):
        if isinstance(obj, NoIndent):
            # Return the value formatted as a compact string, without newlines
            return json.dumps(obj.value, separators=(',',':'))
        return super().default(obj)