lang-json
v1.0.3
Published
A lib for templating json
Downloads
269
Maintainers
Readme
��#� �L�a�n�g�J�S�O�N�
�
�
�
��L�a�n�g�J�S�O�N�
� �i�s� �a� �l�i�g�h�t�w�e�i�g�h�t� �t�e�m�p�l�a�t�i�n�g� �e�n�g�i�n�e� �d�e�s�i�g�n�e�d� �f�o�r� �J�a�v�a�S�c�r�i�p�t� �a�p�p�l�i�c�a�t�i�o�n�s�,� �a�l�l�o�w�i�n�g� �y�o�u� �t�o� �c�r�e�a�t�e� �d�y�n�a�m�i�c� �J�S�O�N� �s�t�r�u�c�t�u�r�e�s� �u�s�i�n�g� �h�e�l�p�e�r� �f�u�n�c�t�i�o�n�s� �a�n�d� �t�e�m�p�l�a�t�e� �s�t�r�i�n�g�s�.� �I�t� �o�f�f�e�r�s� �b�u�i�l�t�-�i�n� �h�e�l�p�e�r�s� �f�o�r� �s�t�r�i�n�g� �m�a�n�i�p�u�l�a�t�i�o�n�,� �m�a�t�h�e�m�a�t�i�c�a�l� �o�p�e�r�a�t�i�o�n�s�,� �l�o�g�i�c�a�l� �c�o�n�d�i�t�i�o�n�s�,� �a�n�d� �m�u�c�h� �m�o�r�e�.�
�
�
�
�#�#� �I�n�s�t�a�l�l�a�t�i�o�n�
�
�
�
�Y�o�u� �c�a�n� �i�n�s�t�a�l�l� ��l�a�n�g�-�j�s�o�n�
� �v�i�a� �n�p�m�:�
�
�
�
��
��b�a�s�h�
�
�n�p�m� �i�n�s�t�a�l�l� �l�a�n�g�-�j�s�o�n�
�
�
��
�
�
�
�
�#�#� �B�a�s�i�c� �I�n�i�t�i�a�l�i�z�a�t�i�o�n� �&� �S�e�t�u�p�
�
�
�
�T�o� �s�t�a�r�t� �u�s�i�n�g� �L�a�n�g�J�S�O�N�,� �i�m�p�o�r�t� �i�t� �i�n�t�o� �y�o�u�r� �p�r�o�j�e�c�t� �a�n�d� �c�r�e�a�t�e� �a�n� �i�n�s�t�a�n�c�e� �o�f� �t�h�e� �c�l�a�s�s�:�
�
�
�
��
��j�a�v�a�s�c�r�i�p�t�
�
�i�m�p�o�r�t� �L�a�n�g�J�S�O�N� �f�r�o�m� �"�l�a�n�g�-�j�s�o�n�"�;�
�
�
�
�c�o�n�s�t� �l�a�n�g�J�S�O�N� �=� �n�e�w� �L�a�n�g�J�S�O�N�(�)�;�
�
�
��
�
�
�
�
�#�#� �U�s�i�n�g� �B�u�i�l�t�-�i�n� �H�e�l�p�e�r�s�
�
�
�
�#�#�#� �E�x�a�m�p�l�e� �1�:� �S�t�r�i�n�g� �M�a�n�i�p�u�l�a�t�i�o�n�
�
�Y�o�u� �c�a�n� �m�a�n�i�p�u�l�a�t�e� �s�t�r�i�n�g�s� �u�s�i�n�g� �b�u�i�l�t�-�i�n� �h�e�l�p�e�r�s�.� �H�e�r�e� s� �h�o�w� �t�o� �c�o�n�v�e�r�t� �a� �s�t�r�i�n�g� �t�o� �u�p�p�e�r�c�a�s�e�:�
�
�
�
��
��j�a�v�a�s�c�r�i�p�t�
�
�c�o�n�s�t� �t�e�m�p�l�a�t�e� �=� �{�
�
� � �"�g�r�e�e�t�i�n�g�"�:� �"�{�{�#�u�p�p�e�r�c�a�s�e� �'�h�e�l�l�o�'�}�}� �w�o�r�l�d�"�
�
�}�;�
�
�
�
�c�o�n�s�t� �d�a�t�a� �=� �{�}�;�
�
�c�o�n�s�t� �r�e�s�u�l�t� �=� �l�a�n�g�J�S�O�N�.�a�p�p�l�y�T�e�m�p�l�a�t�e�(�t�e�m�p�l�a�t�e�,� �d�a�t�a�)�;�
�
�c�o�n�s�o�l�e�.�l�o�g�(�r�e�s�u�l�t�)�;�
�
�/�*�
�
�O�u�t�p�u�t�:�
�
�{�
�
� � �"�g�r�e�e�t�i�n�g�"�:� �"�H�E�L�L�O� �w�o�r�l�d�"�
�
�}�
�
�*�/�
�
�
��
�
�
�
�
�#�#�#� �E�x�a�m�p�l�e� �2�:� �C�o�n�d�i�t�i�o�n�a�l� �S�t�a�t�e�m�e�n�t�s�
�
�U�t�i�l�i�z�e� �t�h�e� �i�f� �h�e�l�p�e�r� �t�o� �c�o�n�d�i�t�i�o�n�a�l�l�y� �r�e�n�d�e�r� �v�a�l�u�e�s� �b�a�s�e�d� �o�n� �a� �v�a�r�i�a�b�l�e�:�
�
�
�
��
��j�a�v�a�s�c�r�i�p�t�
�
�c�o�n�s�t� �t�e�m�p�l�a�t�e� �=� �{�
�
� � �"�s�t�a�t�u�s�"�:� �"�{�{�#�i�f� �i�s�A�c�t�i�v�e� �'�A�c�t�i�v�e�'� �'�I�n�a�c�t�i�v�e�'�}�}�"�
�
�}�;�
�
�
�
�c�o�n�s�t� �d�a�t�a� �=� �{� �i�s�A�c�t�i�v�e�:� �t�r�u�e� �}�;�
�
�c�o�n�s�t� �r�e�s�u�l�t� �=� �l�a�n�g�J�S�O�N�.�a�p�p�l�y�T�e�m�p�l�a�t�e�(�t�e�m�p�l�a�t�e�,� �d�a�t�a�)�;�
�
�c�o�n�s�o�l�e�.�l�o�g�(�r�e�s�u�l�t�)�;�
�
�/�*�
�
�O�u�t�p�u�t�:�
�
�{�
�
� � �"�s�t�a�t�u�s�"�:� �"�A�c�t�i�v�e�"�
�
�}�
�
�*�/�
�
�
��
�
�
�
�
�
�
�#�#�#� �E�x�a�m�p�l�e� �3�:� �L�o�o�p�i�n�g� �T�h�r�o�u�g�h� �A�r�r�a�y�s�
�
�
�
�Y�o�u� �c�a�n� �i�t�e�r�a�t�e� �t�h�r�o�u�g�h� �a�r�r�a�y�s� �u�s�i�n�g� �t�h�e� �e�a�c�h� �h�e�l�p�e�r�:�
�
�
�
��
��j�a�v�a�s�c�r�i�p�t�
�
�c�o�n�s�t� �t�e�m�p�l�a�t�e� �=� �{�
�
� � �"�u�s�e�r�s�"�:� �{�
�
� � � � �"�{�{�#�e�a�c�h� �u�s�e�r�s�}�}�"�:� �{�
�
� � � � � � �"�n�a�m�e�"�:� �"�{�{�#�v�a�r� �i�t�e�m�.�n�a�m�e�}�}�"�,�
�
� � � � � � �"�a�g�e�"�:� �"�{�{�#�v�a�r� �i�t�e�m�.�a�g�e�}�}�"�
�
� � � � �}�
�
� � �}�
�
�}�;�
�
�
�
�c�o�n�s�t� �d�a�t�a� �=� �{�
�
� � �u�s�e�r�s�:� �[�
�
� � � � �{� �n�a�m�e�:� �"�J�o�h�n�"�,� �a�g�e�:� �3�0� �}�,�
�
� � � � �{� �n�a�m�e�:� �"�J�a�n�e�"�,� �a�g�e�:� �2�5� �}�,�
�
� � � � �{� �n�a�m�e�:� �"�D�o�e�"�,� �a�g�e�:� �4�0� �}�
�
� � �]�
�
�}�;�
�
�
�
�c�o�n�s�t� �r�e�s�u�l�t� �=� �l�a�n�g�J�S�O�N�.�a�p�p�l�y�T�e�m�p�l�a�t�e�(�t�e�m�p�l�a�t�e�,� �d�a�t�a�)�;�
�
�c�o�n�s�o�l�e�.�l�o�g�(�r�e�s�u�l�t�)�;�
�
�/�*�
�
�O�u�t�p�u�t�:�
�
�{�
�
� � �"�u�s�e�r�s�"�:� �[�
�
� � � � �{�
�
� � � � � � �"�n�a�m�e�"�:� �"�J�o�h�n�"�,�
�
� � � � � � �"�a�g�e�"�:� �3�0�
�
� � � � �}�,�
�
� � � � �{�
�
� � � � � � �"�n�a�m�e�"�:� �"�J�a�n�e�"�,�
�
� � � � � � �"�a�g�e�"�:� �2�5�
�
� � � � �}�,�
�
� � � � �{�
�
� � � � � � �"�n�a�m�e�"�:� �"�D�o�e�"�,�
�
� � � � � � �"�a�g�e�"�:� �4�0�
�
� � � � �}�
�
� � �]�
�
�}�
�
�*�/�
�
�
��
�
�
�
�
�#�#�#� �E�x�a�m�p�l�e� �4�:� �C�h�a�i�n�i�n�g� �H�e�l�p�e�r�s�
�
�Y�o�u� �c�a�n� �c�h�a�i�n� �m�u�l�t�i�p�l�e� �h�e�l�p�e�r�s� �t�o�g�e�t�h�e�r� �f�o�r� �m�o�r�e� �c�o�m�p�l�e�x� �o�p�e�r�a�t�i�o�n�s�:�
�
�
�
��
��j�a�v�a�s�c�r�i�p�t�
�
�c�o�n�s�t� �t�e�m�p�l�a�t�e� �=� �{�
�
� � �"�m�e�s�s�a�g�e�"�:� �"�{�{�#�u�p�p�e�r�c�a�s�e� �(�c�o�n�c�a�t� �'�h�e�l�l�o�'� �'�,� �w�o�r�l�d�'�)�}�}�"�
�
�}�;�
�
�
�
�c�o�n�s�t� �d�a�t�a� �=� �{�}�;�
�
�c�o�n�s�t� �r�e�s�u�l�t� �=� �l�a�n�g�J�S�O�N�.�a�p�p�l�y�T�e�m�p�l�a�t�e�(�t�e�m�p�l�a�t�e�,� �d�a�t�a�)�;�
�
�c�o�n�s�o�l�e�.�l�o�g�(�r�e�s�u�l�t�)�;�
�
�/�*�
�
�O�u�t�p�u�t�:�
�
�{�
�
� � �"�m�e�s�s�a�g�e�"�:� �"�H�E�L�L�O�,� �W�O�R�L�D�"�
�
�}�
�
�*�/�
�
�
��
�
�
�
�
�#�#� �P�e�r�f�o�r�m�a�n�c�e� �T�i�p�s� �f�o�r� �L�a�r�g�e� �D�a�t�a�
�
�
�
�-� �W�h�e�n� �w�o�r�k�i�n�g� �w�i�t�h� �l�a�r�g�e� �d�a�t�a�s�e�t�s�,� �c�o�n�s�i�d�e�r� �t�h�e�s�e� �p�e�r�f�o�r�m�a�n�c�e� �t�i�p�s�:�
�
�
�
� �-� �U�s�e� �E�f�f�i�c�i�e�n�t� �D�a�t�a� �S�t�r�u�c�t�u�r�e�s�:� �C�h�o�o�s�e� �d�a�t�a� �s�t�r�u�c�t�u�r�e�s� �t�h�a�t� �a�r�e� �o�p�t�i�m�i�z�e�d� �f�o�r� �t�h�e� �o�p�e�r�a�t�i�o�n�s� �y�o�u� �n�e�e�d�,� �s�u�c�h� �a�s� �a�r�r�a�y�s� �f�o�r� �o�r�d�e�r�e�d� �c�o�l�l�e�c�t�i�o�n�s� �a�n�d� �o�b�j�e�c�t�s� �f�o�r� �k�e�y�-�v�a�l�u�e� �p�a�i�r�s�.�
�
�
�
� �-� �L�i�m�i�t� �H�e�l�p�e�r� �C�a�l�l�s�:� �R�e�d�u�c�e� �t�h�e� �n�u�m�b�e�r� �o�f� �h�e�l�p�e�r� �c�a�l�l�s� �i�n�s�i�d�e� �l�o�o�p�s� �o�r� �l�a�r�g�e� �t�e�m�p�l�a�t�e�s�.� �P�r�e�p�r�o�c�e�s�s� �d�a�t�a� �i�f� �p�o�s�s�i�b�l�e� �t�o� �p�a�s�s� �s�i�m�p�l�i�f�i�e�d� �d�a�t�a� �t�o� �t�h�e� �t�e�m�p�l�a�t�e�.�
�
�
�
� �-� �A�v�o�i�d� �D�e�e�p� �N�e�s�t�i�n�g�:� �K�e�e�p� �t�e�m�p�l�a�t�e�s� �f�l�a�t� �w�h�e�n� �p�o�s�s�i�b�l�e� �t�o� �e�n�h�a�n�c�e� �r�e�a�d�a�b�i�l�i�t�y� �a�n�d� �r�e�d�u�c�e� �p�r�o�c�e�s�s�i�n�g� �c�o�m�p�l�e�x�i�t�y�.�
�
�
�
�#�#� �A�v�a�i�l�a�b�l�e� �H�e�l�p�e�r�s�
�
�L�a�n�g�J�S�O�N� �i�n�c�l�u�d�e�s� �a� �v�a�r�i�e�t�y� �o�f� �b�u�i�l�t�-�i�n� �h�e�l�p�e�r�s� �f�o�r� �d�i�f�f�e�r�e�n�t� �p�u�r�p�o�s�e�s�:�
�
�
�
�#�#�#� �S�t�r�i�n�g� �H�e�l�p�e�r�s�
�
� �-� �u�p�p�e�r�c�a�s�e�:� �C�o�n�v�e�r�t�s� �a� �s�t�r�i�n�g� �t�o� �u�p�p�e�r�c�a�s�e�.�
�
� �-� �l�o�w�e�r�c�a�s�e�:� �C�o�n�v�e�r�t�s� �a� �s�t�r�i�n�g� �t�o� �l�o�w�e�r�c�a�s�e�.�
�
� �-� �t�r�i�m�:� �R�e�m�o�v�e�s� �w�h�i�t�e�s�p�a�c�e� �f�r�o�m� �b�o�t�h� �e�n�d�s� �o�f� �a� �s�t�r�i�n�g�.�
�
� �-� �s�u�b�s�t�r�i�n�g�:� �E�x�t�r�a�c�t�s� �a� �s�u�b�s�t�r�i�n�g� �f�r�o�m� �a� �s�t�r�i�n�g�.�
�
� �-� �c�o�n�c�a�t�:� �C�o�n�c�a�t�e�n�a�t�e�s� �m�u�l�t�i�p�l�e� �s�t�r�i�n�g�s�.�
�
�
�
�#�#�#� �M�a�t�h�e�m�a�t�i�c�a�l� �H�e�l�p�e�r�s�
�
�
�
� �-� �a�d�d�:� �A�d�d�s� �t�w�o� �n�u�m�b�e�r�s�.�
�
� �-� �s�u�b�t�r�a�c�t�:� �S�u�b�t�r�a�c�t�s� �o�n�e� �n�u�m�b�e�r� �f�r�o�m� �a�n�o�t�h�e�r�.�
�
� �-� �m�u�l�t�i�p�l�y�:� �M�u�l�t�i�p�l�i�e�s� �t�w�o� �n�u�m�b�e�r�s�.�
�
� �-� �d�i�v�i�d�e�:� �D�i�v�i�d�e�s� �o�n�e� �n�u�m�b�e�r� �b�y� �a�n�o�t�h�e�r�.�
�
�
�
�#�#�#� �L�o�g�i�c�a�l� �H�e�l�p�e�r�s�
�
�
�
� �-� �i�f�:� �E�v�a�l�u�a�t�e�s� �a� �c�o�n�d�i�t�i�o�n� �a�n�d� �r�e�t�u�r�n�s� �o�n�e� �o�f� �t�w�o� �v�a�l�u�e�s�.�
�
� �-� �a�n�d�:� �R�e�t�u�r�n�s� �t�r�u�e� �i�f� �a�l�l� �c�o�n�d�i�t�i�o�n�s� �a�r�e� �t�r�u�e�.�
�
� �-� �o�r�:� �R�e�t�u�r�n�s� �t�r�u�e� �i�f� �a�t� �l�e�a�s�t� �o�n�e� �c�o�n�d�i�t�i�o�n� �i�s� �t�r�u�e�.�
�
�
�
�#�#�#� �D�a�t�e� �a�n�d� �T�i�m�e� �H�e�l�p�e�r�s�
�
� �-� �g�e�t�C�u�r�r�e�n�t�D�a�t�e�:� �R�e�t�u�r�n�s� �t�h�e� �c�u�r�r�e�n�t� �d�a�t�e� �i�n� �I�S�O� �f�o�r�m�a�t�.�
�
� �-� �g�e�t�C�u�r�r�e�n�t�T�i�m�e�:� �R�e�t�u�r�n�s� �t�h�e� �c�u�r�r�e�n�t� �t�i�m�e� �i�n� �l�o�c�a�l� �f�o�r�m�a�t�.�
�
�
�
�#�#�#� �A�r�r�a�y� �H�e�l�p�e�r�s�
�
�
�
� �-� �a�r�r�a�y�L�e�n�g�t�h�:� �R�e�t�u�r�n�s� �t�h�e� �l�e�n�g�t�h� �o�f� �a�n� �a�r�r�a�y�.�
�
� �-� �a�r�r�a�y�I�n�c�l�u�d�e�s�:� �C�h�e�c�k�s� �i�f� �a�n� �a�r�r�a�y� �i�n�c�l�u�d�e�s� �a� �c�e�r�t�a�i�n� �i�t�e�m�.�
�
�
�
�#�#�#� �O�b�j�e�c�t� �H�e�l�p�e�r�s�
�
�
�
� �-� �o�b�j�e�c�t�K�e�y�s�:� �R�e�t�u�r�n�s� �t�h�e� �k�e�y�s� �o�f� �a�n� �o�b�j�e�c�t�.�
�
� �-� �o�b�j�e�c�t�V�a�l�u�e�s�:� �R�e�t�u�r�n�s� �t�h�e� �v�a�l�u�e�s� �o�f� �a�n� �o�b�j�e�c�t�.�
�
�
�
�#�#� �C�o�n�c�l�u�s�i�o�n�
�
�L�a�n�g�J�S�O�N� �p�r�o�v�i�d�e�s� �a� �p�o�w�e�r�f�u�l� �w�a�y� �t�o� �d�y�n�a�m�i�c�a�l�l�y� �g�e�n�e�r�a�t�e� �J�S�O�N� �s�t�r�u�c�t�u�r�e�s� �u�s�i�n�g� �a� �f�l�e�x�i�b�l�e� �t�e�m�p�l�a�t�i�n�g� �s�y�s�t�e�m�.� �W�h�e�t�h�e�r� �y�o�u�'�r�e� �w�o�r�k�i�n�g� �w�i�t�h� �s�i�m�p�l�e� �s�t�r�i�n�g�s� �o�r� �c�o�m�p�l�e�x� �d�a�t�a� �s�t�r�u�c�t�u�r�e�s�,� �L�a�n�g�J�S�O�N� �o�f�f�e�r�s� �a� �r�a�n�g�e� �o�f� �b�u�i�l�t�-�i�n� �h�e�l�p�e�r�s� �t�o� �s�t�r�e�a�m�l�i�n�e� �y�o�u�r� �d�e�v�e�l�o�p�m�e�n�t� �p�r�o�c�e�s�s�.�