Metadata-Version: 2.1
Name: JSONAutoArray
Version: 1.0.1
Summary: Write array to self-closing JSON file
Home-page: https://gitlab.com/doug.shawhan/json-autoarray
Author: Doug Shawhan
Author-email: doug.shawhan@gmail.com
Maintainer: Doug Shawhan
Maintainer-email: doug.shawhan@gmail.com
License: Copyright 2014 Doug Shawhan
        
        Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
Download-URL: https://gitlab.com/doug.shawhan/json-autoarray
Project-URL: Bug Tracker, https://gitlab.com/doug.shawhan/jsonautoarray/
Project-URL: Source Code, https://gitlab.com/doug.shawhan/jsonautoarray/master
Project-URL: Development Version, https://gitlab.com/doug.shawhan/jsonautoarray/dev
Project-URL: Documentation, https://jsonautoarray.readthedocs.io
Description: # json_autoarray
        
        Write JSON-serializable python objects to file as JSON array.
        
        Raises a SerializationError if you send it an object that cannot be serialized by whatever json module you are using..
                
        Tries to use python-cjson (python2.x only) or UltraJSON  for serializing objects, because you wouldn't be needing a silly thing like this if you weren't handling big old objects.
        
        Objects successfully sent to the writer are always contained in an array. JSONAutoArray will always attempt to close the array upon file closure, regardless of any exceptions which may lead to a premature end of your process.
        
        ## Why?
        
        Suppose you are making with the ETL, and are pulling objects from a janky stream. Should your stream close prematurely, or send you some sort of madness, JSONAutoArray will throw out the bad object, and close the array before closing the file. 
        
        ## Installation
        Install using pip:
        ```bash
        pip install JSONAutoArray
        ```
        
        ## Usage
        ```python
        import random
        from json_autoarray import JSONAutoArray
        
        objects = [ 
        		{"this": "that"},
        		["the", "other"],
        		{"hippie": "joe"},
        		{
        			"facist":{
        				"bullyboy":[
        					"me",
        					"you",
        					"them"
        					]
        			}
        		},
        		set(["a","a","b"]),
        		list(range(3)),
        ]
        
        f = "foo.json"
        with JSONAutoArray.ArrayWriter(f) as writer:
        	for obj in objects:
        		writer.write(obj)
        
        # will fail in python3 if file opened as binary!
        f = open("bar.json", "w")
        with JSONAutoArray.ArrayWriter(f) as writer:
        	for obj in objects:
        		writer.write(obj)
        
        # write ten thousand random flabberdabs
        f = "baz.json"
        with JSONAutoArray.ArrayWriter(f) as writer:
        	try:
        		for i in range(10000):
        			writer.write([
        					{"flabberdab": random.randint(1, 1000)}
        				])
        	except JSONAutoArray.SerializationError as error:
        		print(error)
        
        # close array on StopIteration error
        def rando():
        	yield set([1,1,1,1,1])
        	for i in range(100):
        		yield {
        				"".join([chr(random.randint(1,100)) for i in range(5)]): \
        						random.randint(1,100)}
        
        print("expect uncaught StopIteration")
        with JSONAutoArray.ArrayWriter(open("quux.json", "w")) as writer:
        	try:
        		rg = rando()
        		while True:
        			if sys.version_info[0] < 3:
        				writer.write(rg.next())
        			else:
        				writer.write(next(rg))
        	except JSONAutoArray.SerializationError as error:
        		print(error)
        ```
        
Keywords: ETL,Database
Platform: UNKNOWN
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 3
Description-Content-Type: text/markdown
