# Document the JSON output for each module

**URL:** <https://forum.ansible.com/t/document-the-json-output-for-each-module/16188>\
**Category:** Ansible Project\
**Created:** [September 12, 2014, 5:30am UTC](https://forum.ansible.com/t/document-the-json-output-for-each-module/16188 "2014-09-12T05:30:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Wong](https://avatars.discourse-cdn.com/v4/letter/j/6f9a4e/32.png) [@John\_Wong](https://forum.ansible.com/u/John_Wong)\
**Post date:** [September 12, 2014, 5:30am UTC](https://forum.ansible.com/t/document-the-json-output-for-each-module/16188/1 "2014-09-12T05:30:15Z")

</div>

Problem:  
I found stat module and I was wondering what I could use from the JSON output for my conditional statement.  
I either have to use debug: msg=“{{stat\_output}}” or refer to the code: [https://github.com/ansible/ansible/blob/devel/library/files/stat#L100](https://github.com/ansible/ansible/blob/devel/library/files/stat#L100)

The stat module is pretty neat and compact but other modules aren’t. They are usually long and contains multiple nested if/else.

But basically most people will be looking for module.exit\_json for the success case.

I propose to begin the effort to document the JSON output.

1. But before we do that, what are people’s opinion on this?
2. Should we add the JSON manually to DOCUMENTATION, or should there be a mechanism to automate this?

By automation, there are two ways:

- write a test for each module, run it, pulls the output and add to the documentation  
But this approach has two drawbacks. One modules such as ec2 cannot be run without an ec2 instance, and two  
people who wish to build ansible documentation locally may not be willing to run the tests.

The second method is to define the structure of the success JSON output at the beginning of the function call.  
This way we should be able to QUICKLY pull out the dictionary using the ast module.

But this has two drawback.

1. We will not know whether the user wrote stat or foobar when they call module.exist\_json(changed=True, stat=stat\_dict).
2. We MAY want to cover fail\_json as well, but the keys are not fixed either. For example, the followings are extracted  
from the file module:  
module.fail\_json(path=path, msg=‘Error while replacing: %s’ % str(e))  
module.fail\_json(dest=path, src=src, msg=‘Cannot link, %s exists at destination’ % prev\_state)

I guess we are down to manually adding the JSON output?
