Solved How can i write a JSon file ?

Discussion in 'Mod Support' started by jojos38, Jul 7, 2017.

  1. jojos38

    jojos38
    Expand Collapse

    Joined:
    Oct 22, 2013
    Messages:
    1,059
    I know there is readJsonFile("") but there is something to write a JSon file please ?
     
  2. Matt Super 13

    Matt Super 13
    Expand Collapse

    Joined:
    Jul 5, 2017
    Messages:
    12
    I haven't understood your problem
     
  3. jojos38

    jojos38
    Expand Collapse

    Joined:
    Oct 22, 2013
    Messages:
    1,059
    How to write a value in a JSon file
     
  4. Matt Super 13

    Matt Super 13
    Expand Collapse

    Joined:
    Jul 5, 2017
    Messages:
    12
    Sorry, i don't know how to solve your problem
     
  5. Deleted member 160369

    Deleted member 160369
    Expand Collapse
    Guest

    Json files can be opened and edited with a simple text editor.

    This, for example, is the main info file for the D-Series (info.json):
    Code:
    {
        "Name":"D-Series",
        "Brand":"Gavril",
        "Author":"BeamNG",
        "Country":"United States",
        "Type":"Truck",
      "Body Style":"Pickup",
        "Years":{"min":1988, "max":1994},
        "Derby Class":"Medium Truck",
        "default_pc":"v8_4wd",
        "default_color":"Sea Blue",
        "colors":{
            "Pearl White": "1 1 1 1.2",
            "Charcoal": "0.18 0.18 0.18 1.2",
            "Silver": "0.65 0.65 0.65 1.2",
            "Gray": "0.5 0.5 0.5 1.3",
            "Carbon Gray": "0.33 0.33 0.33 1.3",
            "Cream": "1 0.9 0.8 1.4",
            "Light Brown": "0.6 0.45 0.35 1.3",
            "Clay Red": "0.45 0.28 0.233 1.3",
            "Jet Black": "0 0 0 1.3",
            "Fire Red": "1 0 0 1.2",
            "Champagne": "0.55 0.5 0.45 1.2",
            "Scarlet Red": "0.68 0.1 0.11 1.3",
            "Flame Orange": "1 0.3 0 1.2",
            "Chestnut": "0.3 0.2 0.12 1.2",
            "Burgundy": "0.5 0 0 1.2",
            "Forest Green": "0.1 0.4 0.2 1.2",
            "Seafoam Green": "0.24 0.48 0.48 1.2",
            "Verdant Green": "0.21 0.55 0.11 1.3",
            "Olive Green": "0.27 0.35 0.23 1.2",
            "Army Green": "0.32 0.35 0.23 1.5",
            "Opal Green": "0.22 0.37 0.33 1.3",
            "Aquamarine": "0.15 0.35 0.6 1.2",
            "Sea Blue": "0.2 0.3 0.6 1.2",
            "Brilliant Blue": "0.05 0.35 0.8 1.2",
            "Royal Blue": "0.0 0.1 0.42 1.3",
            "Solar Yellow": "0.95 0.7 0.1 1.3",
            "Vibrant Red": "0.9 0.05 0.04 1.3",
            "Sunset Purple": "0.20 0.22 0.65 1.3",
            "Pleasant Blue": "0.35 0.50 0.65 1.2",
            "Bermuda Blue": "0.06 0.145 0.17 1.2",
            "Navy Blue": "0.0 0.05 0.25 1.2"
        }
    }
     
    • Like Like x 1
  6. jojos38

    jojos38
    Expand Collapse

    Joined:
    Oct 22, 2013
    Messages:
    1,059
    I know but i want to write a JSon trough the lua code
    --- Post updated ---
    I found
    Code:
    serializeJsonToFile("mods/unpacked/sirenmod/lua/vehicle/extensions/auto/latestConfig.json", "latestConfig")
    but when i do that the json file is clear and there is only: "latestConfig" write on the first line
     
  7. meywue

    meywue
    Expand Collapse
    Administrator
    BeamNG Team

    Joined:
    Nov 19, 2015
    Messages:
    339
    Probably cause you're passing a string rather than an object.
     
  8. thomatoes50

    thomatoes50
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 31, 2013
    Messages:
    722
    remove double quotes on "latestConfig"
     
  9. jojos38

    jojos38
    Expand Collapse

    Joined:
    Oct 22, 2013
    Messages:
    1,059
    Yes but it return me the latestConfig value, so in my json i have: "settings_default"
    --- Post updated ---
    I searched in the game main files and it seem i have to add them in a table... but it give me that:
    [myValue1, myValue2]
    :/
    --- Post updated ---
    For the answer:

    Code:
        local i =       {
                        variableUn = "1",
                        variableDeux = "2"
                      }
       
          serializeJsonToFile("/sirenmod/config/latestConfig.json", i, true)
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice