variable to json ...

Prev Next

Function Names

variable to json

Description

This function loads JSON contents from a text string into a variable. This approach is useful if JSON text has been obtained from other sources, for example a table.

If the specified variable is existing then all contents will be deleted before the loading procedure starts. The members (and sub-members) will be built up while loading / reading in is in progress.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

1, 3

Parameters

No.TypeDescription
1, etc.
code
variable
:string
Source variable name

The contents will be loaded into this variable.

Opt. 2
input
string JSON Format

Following values are supported: JSON: Save JSON in nice format with every item in a separate line and text indentation used
JSON compact: Save JSON in condensed format without indentation and line breaks in order reduce overall size but without loosing any data

Default value: JSON

Return value

TypeDescription
string JSON contents

Contains JSON text of saved variable

Examples

       a[] = Hello World;
       j[] = variable to json( a[] );
       echo("Simple variable in JSON: ", j[] );
       json to variable( b[], j[], JSON B4P );
       see(b[]);

Output

Simple variable in JSON: [ "Hello World"]
b[]                     Hello World                (quoted string,full access)

Try it yourself: Open LIB_Function_variable_to_json.b4p in B4P_Examples.zip. Decompress before use.

See also

variable save
json to variable