FromJson method

Official Content
This documentation is valid for:

Loads a variable based on a Structured Data Type (SDT) or Business Component from a JSON string received as a parameter.


[&Boolean =] &var.FromJson(&String[, &Messages])

    Attribute or variable string with the JSON content.

    Variable based on an SDT or Business Component.

   Variable based on the GeneXus's Messages data type. In case of an error, it will contain the error information. This Parameter is optional. 

Type returned:
    It returns False in case of having an error; otherwise, it returns True. The assignment of the return value is optional. 


Objects: ProcedureTransactionWeb Panel, Panel
Generators: .NET Framework .NET, Java


The FromJson method loads the &var structure from the &String variable content. The variable's JSON format (&String) must be compatible with the variable based on an SDT or Business Component structure (&var).


Consider a Structured Data Type defined as follows:

     NumericMember: Numeric
     CharacterMember: Character
     GeoPointMember: GeoPoint

Define the following code (for example in a Procedure Source or in a Web Panel / Panel Event):

 &VarBasedOnSDT1.FromJson('[{"NumericMember": 0,"CharacterMember":"ValueCharacter","GeoPointMember":"POINT(-56.10 -33.01)"}]')

The above code initializes the &VarBasedOnSDT1 variable.

Note that the GeoPointMember receives a value in WellKnowText Format (WKT). Another alternative, only available when generating for Android, is to pass a Geolocation domain format as parameter, as follows:

&VarBasedOnSDT1.FromJson('[{"NumericMember": 0,"CharacterMember":"VallueCharacter","GeoPointMember":"57.10, 68.9"}]')

Technical Details

Data Type Mapping

The GeneXus basic data types are mapped to JSON data types in this way:

  • Character, VarChar, LongVarChar → JSON string
  • Boolean → JSON Boolean
  • Numeric → JSON Number
  • Collections → an ordered sequence of values, comma-separated and enclosed in square brackets

Ignored SDT Properties

The following properties are ignored in the process of serializing an SDT to JSON:


See Also

ToJson Method
Structured Data Type (SDT) object