import json
from pprint import pprint

def pathparser(path, separator="."):
        return path.split(separator)

def pathquery(pson, path, separator=".", missing=None, iterate=True):
        if isinstance(path,str) or isinstance(path, unicode):
                path = pathparser(path, separator=separator)

        counter = 0
        for token in path:
                if type(pson) == dict and pson.has_key(token): # step one level deeper into the pson with our token
                        pson = pson[token]
                elif type(pson) == list:
                        # if we hit an array see if the token is a number else assume we
                        # want the rest of the path applied to every element in the array
                        try:
                                if int(token)<len(pson):
                                        pson = pson[int(token)]
                                else: #handle a number longer than list len
                                        return missing
                        except ValueError:
                                if iterate:
                                        return [pathquery(x, path[counter:]) for x in pson]
                                return missing
                else:
                        return missing
                counter += 1

        return pson


import json
from pprint import pprint

def pathparser(path, separator="."):
    return path.split(separator)

def pathquery(pson, path, separator=".", missing=None, iterate=True):
    if isinstance(path,str) or isinstance(path, unicode):
        path = pathparser(path, separator=separator)

    counter = 0
    for token in path:
        # step one level deeper into the pson with our token
        if type(pson) == dict and pson.has_key(token):
            pson = pson[token]
        elif type(pson) == list:
            # if we hit an array see if the token is a number else assume we
            # want the rest of the path applied to every element in the array
            try:
                if int(token)<len(pson):
                    pson = pson[int(token)]
                else: #handle a number longer than list len
                    return missing
            except ValueError:
                if iterate:
                    return [pathquery(x, path[counter:]) for x in pson]
                return missing
        else:
            return missing
        counter += 1

    return pson

Add consistent 4 space indentation
Add consistent 4 space indentation

Applied 4 space indentation all along the main pson.py file.

  import json
  from pprint import pprint
  
  def pathparser(path, separator="."):
-         return path.split(separator)
+     return path.split(separator)
  
  def pathquery(pson, path, separator=".", missing=None, iterate=True):
-         if isinstance(path,str) or isinstance(path, unicode):
+     if isinstance(path,str) or isinstance(path, unicode):
-                 path = pathparser(path, separator=separator)
+         path = pathparser(path, separator=separator)
  
-         counter = 0
+     counter = 0
-         for token in path:
+     for token in path:
-                 if type(pson) == dict and pson.has_key(token): # step one level deeper into the pson with our token
+         # step one level deeper into the pson with our token
+         if type(pson) == dict and pson.has_key(token):
-                         pson = pson[token]
+             pson = pson[token]
-                 elif type(pson) == list:
+         elif type(pson) == list:
-                         # if we hit an array see if the token is a number else assume we
+             # if we hit an array see if the token is a number else assume we
-                         # want the rest of the path applied to every element in the array
+             # want the rest of the path applied to every element in the array
-                         try:
+             try:
-                                 if int(token)<len(pson):
+                 if int(token)<len(pson):
-                                         pson = pson[int(token)]
+                     pson = pson[int(token)]
-                                 else: #handle a number longer than list len
+                 else: #handle a number longer than list len
-                                         return missing
-                         except ValueError:
-                                 if iterate:
-                                         return [pathquery(x, path[counter:]) for x in pson]
-                                 return missing
-                 else:
-                         return missing
+                     return missing
+             except ValueError:
+                 if iterate:
+                     return [pathquery(x, path[counter:]) for x in pson]
+                 return missing
+         else:
+             return missing
-                 counter += 1
+         counter += 1
  
-         return pson
+     return pson
  
- 
Add consistent 4 space indentation
## Code Before:
import json
from pprint import pprint

def pathparser(path, separator="."):
        return path.split(separator)

def pathquery(pson, path, separator=".", missing=None, iterate=True):
        if isinstance(path,str) or isinstance(path, unicode):
                path = pathparser(path, separator=separator)

        counter = 0
        for token in path:
                if type(pson) == dict and pson.has_key(token): # step one level deeper into the pson with our token
                        pson = pson[token]
                elif type(pson) == list:
                        # if we hit an array see if the token is a number else assume we
                        # want the rest of the path applied to every element in the array
                        try:
                                if int(token)<len(pson):
                                        pson = pson[int(token)]
                                else: #handle a number longer than list len
                                        return missing
                        except ValueError:
                                if iterate:
                                        return [pathquery(x, path[counter:]) for x in pson]
                                return missing
                else:
                        return missing
                counter += 1

        return pson


## Instruction:
Add consistent 4 space indentation
## Code After:
import json
from pprint import pprint

def pathparser(path, separator="."):
    return path.split(separator)

def pathquery(pson, path, separator=".", missing=None, iterate=True):
    if isinstance(path,str) or isinstance(path, unicode):
        path = pathparser(path, separator=separator)

    counter = 0
    for token in path:
        # step one level deeper into the pson with our token
        if type(pson) == dict and pson.has_key(token):
            pson = pson[token]
        elif type(pson) == list:
            # if we hit an array see if the token is a number else assume we
            # want the rest of the path applied to every element in the array
            try:
                if int(token)<len(pson):
                    pson = pson[int(token)]
                else: #handle a number longer than list len
                    return missing
            except ValueError:
                if iterate:
                    return [pathquery(x, path[counter:]) for x in pson]
                return missing
        else:
            return missing
        counter += 1

    return pson
