You could also loop through all fields and output it depending on the field-type.
Example:
{% spaceless %}
[
{% for entry in craft.entries.section('news').limit(1) %}
{
{# General Fields #}
'slug': {{ entry.slug | json_encode() | raw }},
'postDate': {{ entry.postDate | json_encode() | raw }},
'title': {{ entry.title | json_encode() | raw }},
'author': {{ entry.author.name | json_encode() | raw }},
{# Your Fields #}
{% for field in entry.getType().getFieldLayout().getFields() %}
{% set field_attr = attribute(entry, field.field.handle) %}
{% switch field.field.type %}
{% case 'Assets' %}
"{{ field.field.handle | escape('js') }}": { {% for asset in field_attr %} { 'title': {{ asset.title | json_encode() | raw }}, 'url': {{ asset.url | json_encode() | raw }} }, {% else %}null{% endfor %} },
{% case 'Categories' %}
"{{ field.field.handle | escape('js') }}": { {% for category in field_attr %} { 'title': {{ category.title | json_encode() | raw }} }, {% else %}null{% endfor %} },
{% case 'Checkboxes' %}
"{{ field.field.handle | escape('js') }}": { {% for option in field_attr %} { 'label': {{ option.label | json_encode() | raw }}, 'value': {{ option.value | json_encode() | raw }} }, {% else %}null{% endfor %} },
{% case 'Date' %}
"{{ field.field.handle | escape('js') }}": {{ field_attr | json_encode() | raw }},
{% case 'DropDown' %}
"{{ field.field.handle | escape('js') }}": { 'label': {{ field_attr.label | json_encode() | raw }}, 'value': {{ field_attr.value | json_encode() | raw }} },
{% case 'Entries' %}
"{{ field.field.handle | escape('js') }}": { {% for field_entry in field_attr %} { 'title': {{ field_entry.title | json_encode() | raw }}, 'slug': {{ field_entry.slug | json_encode() | raw }}, 'url': {{ field_entry.url | json_encode() | raw }} }, {% else %}null{% endfor %} },
{% case 'Matrix' %}
"{{ field.field.handle | escape('js') }}": {{ 'This is a matrix-field' | json_encode() | raw }},
{% case 'MultiSelect' %}
"{{ field.field.handle | escape('js') }}": { {% for option in field_attr %} { 'label': {{ option.label | json_encode() | raw }}, 'value': {{ option.value | json_encode() | raw }} }, {% else %}null{% endfor %} },
{% case 'Radiobutton' %}
"{{ field.field.handle | escape('js') }}": { 'label': {{ field_attr.label | json_encode() | raw }}, 'value': {{ field_attr.value | json_encode() | raw }} },
{% case 'Tags' %}
"{{ field.field.handle | escape('js') }}": { {% for tag in field_attr %} { 'name': {{ tag.name | json_encode() | raw }} }, {% else %}null{% endfor %} },
{% case 'Users' %}
"{{ field.field.handle | escape('js') }}": { {% for user in field_attr %} { 'name': {{ user.name | json_encode() | raw }}, 'id': {{ user.id | json_encode() | raw }} }, {% else %}null{% endfor %} },
{% default %}
"{{ field.field.handle | escape('js') }}": {{ field_attr | json_encode() | raw }},
{% endswitch %}
{% endfor %}
}
{% endfor %}
]
{% endspaceless %}
You might need to customize it, depending on what attributes you need
To make it work with Matrix you'd need to create a Matrix case and copy the whole loop inside that case and set it to use the block var.