variable save ...

Prev Next

Function Names

variable save

Description

This function saves the contents of a variable into a JSON file. If the file is already existin, then the contents will be replaced (and not appended).

Since JSON does not support intermediate nodes in the data trees, but B4P variables do, the base variables at all levels will be put into intermediate arrays containing 2 elements. Element 0 contains the value of the base variable, and Element 1 contains further data up the data tree.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

2, 3

Parameters

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

The contents will be loaded into this variable.

2
input
string File name

This file will be created.

Opt. 3
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

Examples

  b[Green] = Grün;
  b[Blue] = Blau;
  b[Blue,light] = Hellblau;
  b[Blue,dark] = Dunkelblau;

  variable save( b[], "Outputs/colors.json");

  variable load( c[], "Outputs/colors.json", JSON B4P );

  see( c[] );

Output

c[]                     [Void]                     (void,full access)
Blue                    Blau                       (quoted string,full access)
  dark                  Dunkelblau                 (quoted string,full access)
  light                 Hellblau                   (quoted string,full access)
Green                   Grün                       (quoted string,full access)

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

See also

variable load
variable to json