<commit_before>note
    description: "A JSON converter for DS_HASH_TABLE [ANY, HASHABLE]"
    author: "<NAME>"
    date: "$Date: $"
    revision: "$Revision: $"
    file: "$HeadURL: $"

class JSON_DS_HASH_TABLE_CONVERTER

inherit
    JSON_CONVERTER

create
    make

feature {NONE} -- Initialization

    make
        do
            create object.make (0)
        end

feature -- Access

    value: JSON_OBJECT

    object: DS_HASH_TABLE [ANY, HASHABLE]

feature -- Conversion

    from_json (j: like value): detachable like object
        local
            keys: ARRAY [JSON_STRING]
            i: INTEGER
            h: HASHABLE
            a: ANY
        do
            keys := j.current_keys
            create Result.make (keys.count)
            from
                i := 1
            until
                i > keys.count
            loop
                h ?= json.object (keys [i], void)
                check h /= Void end
                a := json.object (j.item (keys [i]), Void)
                Result.put (a, h)
                i := i + 1
            end
        end

    to_json (o: like object): like value
        local
            c: DS_HASH_TABLE_CURSOR [ANY, HASHABLE]
            js: JSON_STRING
            jv: JSON_VALUE
            failed: BOOLEAN
        do
            create Result.make
            from
                c := o.new_cursor
                c.start
            until
                c.after
            loop
            	if attached {JSON_STRING} json.value (c.key) as l_key then
            		js := l_key
            	else
                	create js.make_json (c.key.out)
            	end
                jv := json.value (c.item)
                if jv /= Void then
                    Result.put (jv, js)
                else
                    failed := True
                end
                c.forth
            end
            if failed then
                Result := Void
            end
        end

end -- class JSON_DS_HASH_TABLE_CONVERTER<commit_msg>[FIX] Indentation<commit_after>note
    description: "A JSON converter for DS_HASH_TABLE [ANY, HASHABLE]"
    author: "<NAME>"
    date: "$Date: $"
    revision: "$Revision: $"
    file: "$HeadURL: $"

class JSON_DS_HASH_TABLE_CONVERTER

inherit
    JSON_CONVERTER

create
    make

feature {NONE} -- Initialization

    make
        do
            create object.make (0)
        end

feature -- Access

    value: JSON_OBJECT

    object: DS_HASH_TABLE [ANY, HASHABLE]

feature -- Conversion

    from_json (j: like value): detachable like object
        local
            keys: ARRAY [JSON_STRING]
            i: INTEGER
            h: HASHABLE
            a: ANY
        do
            keys := j.current_keys
            create Result.make (keys.count)
            from
                i := 1
            until
                i > keys.count
            loop
                h ?= json.object (keys [i], void)
                check h /= Void end
                a := json.object (j.item (keys [i]), Void)
                Result.put (a, h)
                i := i + 1
            end
        end

    to_json (o: like object): like value
        local
            c: DS_HASH_TABLE_CURSOR [ANY, HASHABLE]
            js: JSON_STRING
            jv: JSON_VALUE
            failed: BOOLEAN
        do
            create Result.make
            from
                c := o.new_cursor
                c.start
            until
                c.after
            loop
                if attached {JSON_STRING} json.value (c.key) as l_key then
                    js := l_key
                else
                    create js.make_json (c.key.out)
                end
                jv := json.value (c.item)
                if jv /= Void then
                    Result.put (jv, js)
                else
                    failed := True
                end
                c.forth
            end
            if failed then
                Result := Void
            end
        end

end -- class JSON_DS_HASH_TABLE_CONVERTER
{'fraction_non_alphanumeric': 0.07302533532041729, 'fraction_numerical': 0.0014903129657228018, 'mean_word_length': 1.0566905005107252, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '823042', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1102, 'n_words': 326}