Use string concatenation.

String message = "this is value  want to pass to the ActualMessage attribute " ;
String input = "{\r\n" + 
               "\"Level\": 0,\r\n" + 
               "\"Name\": \"String\",\r\n" + 
               "\"msgName\": \"String\",\r\n" + 
               "\"ActualMessage\": \"" + message + "\",\r\n" + 
               "\"TimeStamp\": \"/Date(-62135596800000-0000)/\"\r\n" + 
               "}" ;
Answer from chockleyc on Stack Overflow
🌐
EyeHunts
tutorial.eyehunts.com › home › how to pass dynamic value in json file
How to pass dynamic value in json file - Tutorial - By EyeHunts
June 15, 2023 - To load and modify a JSON file in a web browser environment, you can make use of asynchronous operations like fetch and promises. Here’s an example: // Example dynamic value const dynamicValue = "OpenAI"; // Fetch the JSON file fetch('data.json') ...
Discussions

How to pass dynamic variable to json string
Hi all. I want to pass variables dynamically into JSON string,but i’m getting an error saying input string was not in correct format though all variables are in type string. Following is the JSON string, “Ref”: [ { “… More on forum.uipath.com
🌐 forum.uipath.com
1
3
August 14, 2019
Passing dynamic value in Json object
i am new in Json/JS, Could you help telling how to pass a a value from js var to Json object as in below case: More on stackoverflow.com
🌐 stackoverflow.com
How to pass dynamic parameters to a REST API from a JSON object of a structure | OutSystems
How to pass dynamic parameters to a REST API from a JSON object of a structure More on outsystems.com
🌐 outsystems.com
June 24, 2022
Creating a json with dynamic values - Stack Overflow
In my code i need to call a web service with a json file as argument. ... the above line is my webservice call.Here the UserId 's value is dynamic For eg.the userId is 1 or userId is 2 or 3 , etc...How do i pass this ID dynamically with a value I get from my program. More on stackoverflow.com
🌐 stackoverflow.com
🌐
InterSystems
docs.intersystems.com › irislatest › csp › docbook › DocBook.UI.Page.cls
Creating and Modifying Dynamic Entities | Using JSON | InterSystems IRIS Data Platform 2025.3
For example, the following dynamic array constructor stores two Unicode characters. At runtime, the literal constructor evaluates each element and stores the evaluated value. The first element is defined in JSON syntax and the second element is an ObjectScript function call, but the resulting stored values are identical:
🌐
Stack Overflow
stackoverflow.com › questions › 27684254 › passing-dynamic-value-in-json-object › 27684386
Passing dynamic value in Json object
var ad_id = JSON.stringify(Adv.get({"name":"Abc"})); console.log(ad_id); O/P is correct - {"incomplete":false,"list":[{"id":1303,"name":"Ad9023"}]} Now here I need to extract value of id and pass it to below command
🌐
ServiceNow Community
servicenow.com › community › developer-forum › set-dynamic-key-value-in-json › m-p › 1467969
Solved: Set dynamic key value in json - ServiceNow Community
August 6, 2019 - var primaryObj = source.u_bp_primary_object_type.toString(); //dynamic values var secondayObj = source.u_bp_secondary_object_type.toString(); //dynamic values var payload = { "app_key": appKey.toString(), "status": source.u_bp_incident_status.toString(), "servicenow_ticket_created": "false" }; payload[primaryObj] = source.u_bp_primary_objects.toString(); payload[secondayObj] = source.u_bp_secondary_objects.toString(); ... var dynamicKey = "value3"; var payload = { "value1": "text1", "value2" : "text2", }; payload[dynamicKey] = "text3"; gs.print(JSON.stringify(payload));
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 6211563 › creating-a-json-with-dynamic-values
Creating a json with dynamic values - Stack Overflow
In my code i need to call a web service with a json file as argument. this.myWebService.call({"UserId" : "1"}); the above line is my webservice call.Here the UserId 's value is dynamic For eg.the userId is 1 or userId is 2 or 3 , etc...How do ...
🌐
Stack Overflow
stackoverflow.com › questions › 27684254 › passing-dynamic-value-in-json-object
Passing dynamic value in Json object - javascript
December 29, 2014 - var getVar = JSON.stringify(Adv.get({"name":"Abc"})); var putVar = { "ad_id":getVar.list[0].id,"name":getVar.list[0].name}; console.log(JSON.stringify(As.put(putVar))); ... What can be learned from viewing the sun on earth during a total eclipse that cannot be studied by spacecraft in orbit? How to only print odd characters of a string in terminal? "for what it's worth — used to say that one/someone is not sure whether something one/someone is about to say will be helpful or valued"
🌐
Stack Overflow
stackoverflow.com › questions › 31314579 › how-to-pass-dynamic-variables-in-json
php - how to pass dynamic variables in json - Stack Overflow
July 9, 2015 - function createOrder($entityid, $customerid, $dateorder, $warehouse, $price, $qty) { $json = '{"orderNo":"$entityid",' . '"customerCode": $customerid,' . '"dateOrdered": "08-07-2015",' . '"warehouseId" : 103,' . '"orderLineList":' . '[' . '"productId": 1000002,' .
🌐
Reddit
reddit.com › r/gamemaker › how to parse json file with dynamic variable
r/gamemaker on Reddit: How to parse JSON file with dynamic variable
October 6, 2022 -

Hi,

The other day, I made a post here about parsing a txt file for a note system in my game, in which the notes were stored in an included txt file.

From there I was recommended to instead use a Json file, which I have created a struct in with keys for each note, which looks something like this:

{
    "note1": "test test test",
    "note2": "blah blah blah",
}

To view the notes in-game, I have two objects: One note object on the floor (Obj_Note_F) which the player interacts with to view the note, and which creates the second object, which is the actual note which is displayed to the screen and has the buffer for the Json file (Obj_Note):

Obj_Note_F Step event:

if (keyboard_check_pressed(vk_enter)) && !instance_exists(Obj_Note)
{
var e = instance_create_layer(vx/3,vy/1.5,"GUI",Obj_Note,{
    //All of these variables are defined in the instance variables of Obj_Note_F
sprite: noteSprite, //The sprite of Obj_Note
note: theNote, //The actual note to parse e.g note1
file: "notes.json", //The Json file
});
}

When the note is created, the Json file is parsed in the create event of Obj_Note, which is as follows:

Obj_Note create event:

var buffer = buffer_load("notes.json");
var contents = buffer_read(buffer, buffer_text);
var notes = json_parse(contents);

if variable_struct_exists(notes,note)
{
    text = notes.note;
}

buffer_delete(buffer);

sprite_index = sprite;

However, when I try and open the note, i am thrown this error:

Variable <unknown_object>.note(100218, -2147483648) not set before reading it.
at gml_Object_Obj_Note_Create_0 (line 7) -        text = notes.note;

I imagine this error has something to with how the note variable is being set upon creation of Obj_Note. In the instance variable of Obj_Note_F, "theNote2 is defined as a string, e.g "note1". However, if i set "note" directly in Obj_Note as note1, it displays the text correctly. However, I cannot set it as that in the instance variable as it will throw an error as being an undefined variable.

Does anyone have a solution to this? Am I missing something completely obvious? Any help would be greatly appreciated.

Thanks.

🌐
Numpyninja
numpyninja.com › post › how-to-parse-dynamic-json-string
How to parse Dynamic JSON String?
December 20, 2021 - We cannot provide a description for this page right now
Top answer
1 of 1
2

This depends a lot on your security goals, and on what kind of user interface you want to offer to the author of these expressions.

Loading variables into the local scope does work, since Python is a very dynamic language. There's a risk though that the variables might re-define existing objects, thus breaking your code – what if there's a variable called len, for example?

Therefore, it's usually safer to avoid running the user input in a Python context. Instead:

  • define a simple programming language for these expressions
  • write an interpreter that executes the expressions

Python does have tools to help here. We can parse strings as Python code via the ast module. This returns a data structure that represents the syntax, and doesn't execute anything (though the parser isn't necessarily safe against malicious inputs). We can take the data structure, walk it, and execute it according to the rules we define – such as by resolving variables only from a dictionary. Example code for Python 3.10:

import ast

def interpret(code: str, variables: dict) -> dict:
  module: ast.Module = ast.parse(code, mode='exec')
  for statement in module.body:
    _interpret_statement(statement, variables)
  return variables

def _interpret_statement(statement: ast.stmt, variables: dict) -> None:
  match statement:
    case ast.Assign(targets=[ast.Name(id=name)], value=value):
      variables[name] = _interpret_expr(value, variables)
      return

    case other:
      raise InterpreterError("Syntax not supported", other)

def _interpret_expr(expr: ast.expr, variables: dict) -> Any:
  match expr:
    case ast.BinOp(left=left_ast, op=op, right=right_ast):
      left = _interpret_expr(left_ast, variables)
      right = _interpret_expr(right_ast, variables)
      return _interpret_binop(left, op, right)

    case ast.Name(id=name):
      return variables[name]

    case ast.Constant(value=(int(value) | float(value))):
      return value

    case other:
      raise InterpreterError("Syntax not supported", other)
    

def _interpret_binop(left: Any, op: ast.operator, right: Any) -> Any:
  match op:
    case ast.Add(): return left + right
    case ast.Sub(): return left - right
    case ast.Mult(): return left * right
    case ast.Div(): return left / right
    case ast.Pow(): return left**right
    case other:
      raise InterpreterError(
        "Operator not supported",
        ast.BinOp(ast.Name("_"), other, ast.Name("_")))

class InterpreterError(Exception):
  def __init__(self, msg: str, code: Optional[ast.AST] = None) -> None:
    super().__init__(msg, code)
    self._msg = msg
    self._code = code

  def __str__(self):
    if self._code:
      return f"{self._msg}: {ast.unparse(self._code)}"
    return self._msg

This can then be used to interpret commands, returning a dictionary with all the variables:

>>> interpret("z = x**2+y**2", {"x": 3, "y": 2})
{'x': 3, 'y': 2, 'z': 13}

While this allows you to interpret the Python code however you want (you control the semantics), you are still limited to Python's syntax. For example, you should use the ** operator for exponentiation, not Python's ^ xor-operator.

If you want your own syntax, then you'll probably have to write your own parser. There are a variety of parsing algorithms and parser generators, but I'm partial to hand-written “recursive descent”. This generally involves writing recursive functions of the form parse(Position) -> Optional[tuple[Position, Value]] that gradually consume the input. I have written an example parser and interpreter using that strategy, and have previously contrasted different parsing approaches in an answer about implementing query languages in a Python program.