Module description

jos -- JSON output stream
The jos module implements an JSON [Javascript Object Notation] writer. JSON is a lightweight data interchange format. See The jos module extends the tos module with extra words, so the tos words can be used on a jos variable. The module checks the use of the writer words in relation to the syntax. If a word is used outside the syntax, an exp-invalid-state exception is thrown.

JSON output stream structure

jos% ( -- n )
Get the required space for a jos writer variable

JSON output stream creation, initialisation and destruction

jos-init ( jos -- )
Initialise an empty output stream
jos-(free) ( tos -- )
Free the stream data from the heap
jos-create ( "<spaces>name" -- ; -- jos )
Create a named JSON output stream in the dictionary
jos-new ( -- jos )
Create a new JSON output stream on the heap
jos-free ( jos -- )
Free the JSON output stream from the heap

json writer words

jos-write-start-object ( jos -- )
Write the start of an object
jos-write-end-object ( jos -- )
Write the end of an object
jos-write-start-array ( jos -- )
Write the start of an array
jos-write-end-array ( jos -- )
Write the end of an array
jos-write-name ( c-addr u jos -- )
Write a name
jos-write-string ( c-addr u jos -- )
Write a string value
jos-write-number ( n jos -- )
Write a number as value
jos-write-double ( d jos -- )
Write a double as value
jos-write-float ( r jos -- )
Write a float as value
jos-write-boolean ( flag jos -- )
Write a boolean as value
jos-write-nil ( jos -- )
Write the nil pointer as value
jos-dump ( jos -- )
Dump the jos variable


\ ==============================================================================
\          jos_expl - the json output stream example in the ffl
\               Copyright (C) 2010  Dick van Oudheusden
\ This library is free software; you can redistribute it and/or
\ modify it under the terms of the GNU General Public
\ License as published by the Free Software Foundation; either
\ version 2 of the License, or (at your option) any later version.
\ This library is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ General Public License for more details.
\ You should have received a copy of the GNU General Public
\ License along with this library; if not, write to the Free
\ Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
\ ==============================================================================
\  $Date: 2008-01-13 08:09:33 $ $Revision: 1.3 $
\ ==============================================================================

include ffl/jos.fs

\ Example : Write json output

\ Create the json output stream in the dictionary

jos-create jos1

jos1 jos-write-start-object           \ Write the start of a json object 

s" number" jos1 jos-write-name        \ Write a number with its value
5          jos1 jos-write-number

s" array"  jos1 jos-write-name        \ Write an array with three members
           jos1 jos-write-start-array
7          jos1 jos-write-number
true       jos1 jos-write-boolean
s" hello"  jos1 jos-write-string
           jos1 jos-write-end-array

jos1 jos-write-end-object             \ Write the end of the object

jos1 str-get type cr                  \ Type the json output

Generated by fsdocgen 0.1.0