Skip to content

Json parsing is not working as before #684

Closed

Description

@BrunoDatoMeneses

The conversion of a json file into a map usin unkown type is not working anymore.

Example of code :

map<string, unknown> PARAMETERS_MAP;
JSON_FILE <-  json_file(PARAMETERS_PATH);
PARAMETERS_MAP <-  JSON_FILE.contents;
step <-  float(PARAMETERS_MAP["simulation"]["simulationStep"])  #s; 

GAMA IDE shows this error :

Image

I tried this fix :

step <-  float(map<string, map<string, float>>(PARAMETERS_MAP)["simulation"]["simulationStep"])  #s;

The IDE doesn't show an error anymore but this time I have this error when executing the code

Image

Desktop

  • OS: windows 11
  • GAMA version: 2025.5.6-SNAPSHOT

Parameters file :
parameters.json

Activity

  1. lesquoyb commented on May 26, 2025

    @lesquoyb
    Contributor

    Hello, I've tested your example and everything seems to be working as expected. The only difference is that now typing is more strict than before, so you have to explicitly convert PARAMETERS_MAP["simulation"] into a map to be able to use the [ ] operator on it.
    Here is an example:

    model NewModel
    
    global{
    	
    	json_file parameters_json_file <- json_file("../includes/parameters.json");
    	init {		
    		map<string, unknown> PARAMETERS_MAP;
    		json_file JSON_FILE <-  json_file(parameters_json_file);
    		PARAMETERS_MAP <- JSON_FILE.contents;
    		step <- float(map(PARAMETERS_MAP["simulation"])["simulationStep"]) #s; 
    		write step;
    	}
    	
    }
    
    experiment exp;
    

    Let me know if it fixed your problem

  2. moved this from Todo to To Test in GAMA 2025-06on May 26, 2025
  3. lesquoyb commented on May 26, 2025

    @lesquoyb
    Contributor

    And your attempt to fix was failing because gama tried to convert your whole json into a map<string, map<string, float>>, which doesn't work as not all values in the json are maps of float

  4. BrunoDatoMeneses commented on May 27, 2025

    @BrunoDatoMeneses
    Author

    It worked ! Thank you !

  5. moved this from To Test to Done in GAMA 2025-06on May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    About GAMLThis issue concerns the GAML languageQuestion

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions