<commit_before>package com.jsonerrorparser;

import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * Created by alex on 3/31/17.
 */

public class Parser {

    private static final String TAG = Parser.class.getSimpleName();

    private static Map<String, Object> clearedMap = new HashMap<>();
    private static Map<String, Object> notClearedMap = new HashMap<>();
    private static String source;

    public static String parse(String stringJson) {
        String errorMessage = "";
        errorMessage = simpleParsing(stringJson);
        return errorMessage;
    }

    private static String simpleParsing(String stringJson) {
        source = stringJson;
        String errorKey = "";
        String message = "";
        try {
            int defaultValueIndex = 0;
            JSONObject jsonObject = new JSONObject(stringJson);
            Iterator<String> keys = jsonObject.keys();

            message = jsonObject.getJSONArray(keys.next()).get(defaultValueIndex).toString();

            //return message;
//            for (Iterator<String> iter = jsonObject.keys(); iter.hasNext(); ) {
//                errorKey = iter.next();
//            }
            Iterator<String> iter = jsonObject.keys();
            errorKey = iter.next();
            if (!isNullOrEmpty(errorKey) && !errorKey.equals("non_field_errors")) {
//                Log.d(TAG, "parsed JSONArray");
                return errorKey + " - " + message;
            } else {
                return message;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        try {
            JSONObject jsonObject = new JSONObject(stringJson);
            Iterator<String> keys = jsonObject.keys();

            message = jsonObject.getString(keys.next());
            //return message;
            for (Iterator<String> iter = jsonObject.keys(); iter.hasNext(); ) {
                errorKey = iter.next();
            }
            if (!isNullOrEmpty(errorKey) && !errorKey.equals("non_field_errors")) {
//                Log.d(TAG, "parsed JSONObject");
                return errorKey + " - " + message;
            } else {
                return message;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return "";
    }
<commit_msg>uncommented logging<commit_after>package com.jsonerrorparser;

import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * Created by alex on 3/31/17.
 */

public class Parser {

    private static final String TAG = Parser.class.getSimpleName();

    private static Map<String, Object> clearedMap = new HashMap<>();
    private static Map<String, Object> notClearedMap = new HashMap<>();
    private static String source;

    public static String parse(String stringJson) {
        String errorMessage = "";
        errorMessage = simpleParsing(stringJson);
        return errorMessage;
    }

    private static String simpleParsing(String stringJson) {
        source = stringJson;
        String errorKey = "";
        String message = "";
        try {
            int defaultValueIndex = 0;
            JSONObject jsonObject = new JSONObject(stringJson);
            Iterator<String> keys = jsonObject.keys();

            message = jsonObject.getJSONArray(keys.next()).get(defaultValueIndex).toString();

            //return message;
//            for (Iterator<String> iter = jsonObject.keys(); iter.hasNext(); ) {
//                errorKey = iter.next();
//            }
            Iterator<String> iter = jsonObject.keys();
            errorKey = iter.next();
            if (!isNullOrEmpty(errorKey) && !errorKey.equals("non_field_errors")) {
                Log.d(TAG, "parsed JSONArray");
                return errorKey + " - " + message;
            } else {
                return message;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        try {
            JSONObject jsonObject = new JSONObject(stringJson);
            Iterator<String> keys = jsonObject.keys();

            message = jsonObject.getString(keys.next());
            //return message;
            for (Iterator<String> iter = jsonObject.keys(); iter.hasNext(); ) {
                errorKey = iter.next();
            }
            if (!isNullOrEmpty(errorKey) && !errorKey.equals("non_field_errors")) {
                Log.d(TAG, "parsed JSONObject");
                return errorKey + " - " + message;
            } else {
                return message;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return "";
    }

{'fraction_non_alphanumeric': 0.11635345861655338, 'fraction_numerical': 0.0023990403838464614, 'mean_word_length': 1.9815256257449345, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '4325965', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1283, 'n_words': 307}