<commit_before>JSONxs
======

JSONxs is a Python library that uses a path expression string to get and
set values in JSON and Python datastructures. It's slightly similar to
JSONPath, but supports only simpler expressions and allows
modifications.

JSONxs is safe to use with untrusted input.

Examples
--------

Given the folowing datastructure:

::

    d = {
      'feed': {
        'id': 'my_feed',
        'url': 'http://example.com/feed.rss',
        'tags': ['devel', 'example', 'python'],
        'short.desc': 'A feed',
      }
    }

We can get, set and delete values from the stucture.

::

    jsonxs(d, 'feed.id')                                  # Get the 'id' field: 'my_feed'
    jsonxs(d, 'feed.tags')                                # Get the list of tags.
    jsonxs(d, 'feed.tags[-1]')                            # Get the last item in the 'tags' list: 'python'
    jsonxs(d, 'feed.short\.desc')                         # Escape special char
    jsonxs(d, 'feed.long\.desc', default='N/A')           # Return default when key not found
    jsonxs(d, 'feed.id', ACTION_SET, 'your_feed')         # Set feed id to 'your_feed'
    jsonxs(d, 'feed.tags[-1]', ACTION_SET, 'javascript')  # Replace 'python' with 'javascript'
    jsonxs(d, 'feed.tags[0]', ACTION_DEL)                 # Delete the first tag
    jsonxs(d, 'feed.url', ACTION_DEL)                     # Delete the 'url' key from a dict
    jsonxs(d, 'feed.tags', ACTION_APPEND, 'programming')  # Append 'programming' to tags
    jsonxs(d, 'feed.tags[1]', ACTION_INSERT, 'tech')      # Insert 'tech' at pos 1 in tags
    jsonxs(d, 'feed.author', ACTION_SET, '<NAME>') # Create new key/string value in dict 
    jsonxs(d, 'feed.details', ACTION_MKDICT)              # Create new key/dict value in dict
    jsonxs(d, 'feed.details', ACTION_MKLIST)              # Create new key/list value in dict

Installation and usage
----------------------

To install:

::

    pip install jsonxs

To use:

::

    import jsonxs

    data = {'foo': 1}
    jsonxs.jsonxs(data, 'bar', jsonxs.ACTION_SET, 2)
    print data  # {'foo': 1, 'bar': 2}


License
-------

JSONxs is licensed under the MIT license:

Copyright (c) 2015 <NAME> (<EMAIL>)

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included<commit_msg>Document how to run tests<commit_after>JSONxs
======

JSONxs is a Python library that uses a path expression string to get and
set values in JSON and Python datastructures. It's slightly similar to
JSONPath, but supports only simpler expressions and allows
modifications.

JSONxs is safe to use with untrusted input.

Examples
--------

Given the folowing datastructure:

::

    d = {
      'feed': {
        'id': 'my_feed',
        'url': 'http://example.com/feed.rss',
        'tags': ['devel', 'example', 'python'],
        'short.desc': 'A feed',
      }
    }

We can get, set and delete values from the stucture.

::

    jsonxs(d, 'feed.id')                                  # Get the 'id' field: 'my_feed'
    jsonxs(d, 'feed.tags')                                # Get the list of tags.
    jsonxs(d, 'feed.tags[-1]')                            # Get the last item in the 'tags' list: 'python'
    jsonxs(d, 'feed.short\.desc')                         # Escape special char
    jsonxs(d, 'feed.long\.desc', default='N/A')           # Return default when key not found
    jsonxs(d, 'feed.id', ACTION_SET, 'your_feed')         # Set feed id to 'your_feed'
    jsonxs(d, 'feed.tags[-1]', ACTION_SET, 'javascript')  # Replace 'python' with 'javascript'
    jsonxs(d, 'feed.tags[0]', ACTION_DEL)                 # Delete the first tag
    jsonxs(d, 'feed.url', ACTION_DEL)                     # Delete the 'url' key from a dict
    jsonxs(d, 'feed.tags', ACTION_APPEND, 'programming')  # Append 'programming' to tags
    jsonxs(d, 'feed.tags[1]', ACTION_INSERT, 'tech')      # Insert 'tech' at pos 1 in tags
    jsonxs(d, 'feed.author', ACTION_SET, '<NAME>') # Create new key/string value in dict 
    jsonxs(d, 'feed.details', ACTION_MKDICT)              # Create new key/dict value in dict
    jsonxs(d, 'feed.details', ACTION_MKLIST)              # Create new key/list value in dict

Installation and usage
----------------------

To install:

::

    pip install jsonxs

To use:

::

    import jsonxs

    data = {'foo': 1}
    jsonxs.jsonxs(data, 'bar', jsonxs.ACTION_SET, 2)
    print data  # {'foo': 1, 'bar': 2}


Development
-----------

To run the tests:

::

    $ python jsonxs/jsonxs.py -v


License
-------

JSONxs is licensed under the MIT license:

Copyright (c) 2015 <NAME> (<EMAIL>)

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
{'fraction_non_alphanumeric': 0.12357723577235773, 'fraction_numerical': 0.004697380307136405, 'mean_word_length': 2.532865347798341, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2160813', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1612, 'n_words': 623}