Using JDK 15

Text Blocks : Text blocks start with a โ€œโ€โ€ (three double-quote marks) followed by optional whitespaces and a newline.

Please find the solution below to convert json to string and vice-versa, it might help you in some way.

public class Test {
  public static void main(String[] args) throws JsonProcessingException {
    String s = """
        {
        "students":[{
        "name": "Albert",
        "code":"GE",
        "marks":[{"mark":"20"},{"mark":"40"}]},
        {
        "name": "Gert",
        "code":"LE",
        "marks":[{"mark":"26"}]},
        {
        "name": "John"
        },
        {
        "name": "John Doe",
        "code":"LP",
        "marks":[{"mark":"40"}]}
        ]
        }
        """;
    //JSON TO STRING
    ObjectMapper mapper = new ObjectMapper();
    String s2 = mapper.writeValueAsString(s);
    System.out.println("JSON TO STRING:" + s2);

    //STRING TO JSON
    String s3 = mapper.readValue(s2, new TypeReference<>() {});
    System.out.println("STRING TO JSON:" + s3);

  }
}

Output:

 JSON TO STRING:"{\n\"students\":[{\n\"name\": \"Albert\",\n\"code\":\"GE\",\n\"marks\":[{\"mark\":\"20\"},{\"mark\":\"40\"}]},\n{\n\"name\": \"Gert\",\n\"code\":\"LE\",\n\"marks\":[{\"mark\":\"26\"}]},\n{\n\"name\": \"John\"\n},\n{\n\"name\": \"John Doe\",\n\"code\":\"LP\",\n\"marks\":[{\"mark\":\"40\"}]}\n]\n}\n"
    STRING TO JSON:{
    "students":[{
    "name": "Albert",
    "code":"GE",
    "marks":[{"mark":"20"},{"mark":"40"}]},
    {
    "name": "Gert",
    "code":"LE",
    "marks":[{"mark":"26"}]},
    {
    "name": "John"
    },
    {
    "name": "John Doe",
    "code":"LP",
    "marks":[{"mark":"40"}]}
    ]
    }
Answer from iamgirdhar on Stack Overflow
๐ŸŒ
Jsontostring
jsontostring.com
Convert JSON to String Online
Copy the entire text you want to convert from your JSON file. Once you are done with it, paste your content in the text box available on the website. Click on the option โ€œStringโ€ in order to convert your text from the JSON file to String.
JSONpath
Jsonpath - Using this tool to learn jsonpath syntax, jsonpath array, notation, json path query and json path quickly and easily? To Know more about conversion by checking here.
JSON Dump
json dump - Using this tool to learn dump in json, python json dump, dump in python quickly and easily? To Know more about json by checking here.
JSON Schema
json schema - Using this tool to learn schema json, json schema example, json schema format quickly and easily? To Know more about json by checking here.
JSON To One Line
Json to single line converter online tool - Using this tool to convert json to 1 line, one line json, convert json to one line and json to oneline quickly and easily? To Know more about conversion by checking here.
๐ŸŒ
Text-Utils
text-utils.com โ€บ json formatter
JSON Formatter & JSON To One Line - Online Formatters | Text-Utils.com
September 6, 2025 - This Online JSON Formatter tool can be used to convert JSON to one line or format it using a specified level of indentation.
๐ŸŒ
JSON Formatter
jsonformatter.org โ€บ json-to-one-line
JSON to One Line to convert multiline JSON to one single liner
JSON to One Line is very unique tool for convert Multiline JSON Data to Single Line Online.
๐ŸŒ
JSON Formatter
jsonformatter.net โ€บ home โ€บ json to one line converter
JSON to One Line Converter: JSON to Single Line
February 2, 2023 - Use โ€œchoose a fileโ€ functionality to upload JSON file and download single line JSON file by clicking on Download button. ... Step 1: Copy and paste the JSON code or upload your JSON file. Step 2: Click on the โ€œConvert to One Lineโ€ button to convert multiline to single line JSON code.
Top answer
1 of 4
1

Using JDK 15

Text Blocks : Text blocks start with a โ€œโ€โ€ (three double-quote marks) followed by optional whitespaces and a newline.

Please find the solution below to convert json to string and vice-versa, it might help you in some way.

public class Test {
  public static void main(String[] args) throws JsonProcessingException {
    String s = """
        {
        "students":[{
        "name": "Albert",
        "code":"GE",
        "marks":[{"mark":"20"},{"mark":"40"}]},
        {
        "name": "Gert",
        "code":"LE",
        "marks":[{"mark":"26"}]},
        {
        "name": "John"
        },
        {
        "name": "John Doe",
        "code":"LP",
        "marks":[{"mark":"40"}]}
        ]
        }
        """;
    //JSON TO STRING
    ObjectMapper mapper = new ObjectMapper();
    String s2 = mapper.writeValueAsString(s);
    System.out.println("JSON TO STRING:" + s2);

    //STRING TO JSON
    String s3 = mapper.readValue(s2, new TypeReference<>() {});
    System.out.println("STRING TO JSON:" + s3);

  }
}

Output:

 JSON TO STRING:"{\n\"students\":[{\n\"name\": \"Albert\",\n\"code\":\"GE\",\n\"marks\":[{\"mark\":\"20\"},{\"mark\":\"40\"}]},\n{\n\"name\": \"Gert\",\n\"code\":\"LE\",\n\"marks\":[{\"mark\":\"26\"}]},\n{\n\"name\": \"John\"\n},\n{\n\"name\": \"John Doe\",\n\"code\":\"LP\",\n\"marks\":[{\"mark\":\"40\"}]}\n]\n}\n"
    STRING TO JSON:{
    "students":[{
    "name": "Albert",
    "code":"GE",
    "marks":[{"mark":"20"},{"mark":"40"}]},
    {
    "name": "Gert",
    "code":"LE",
    "marks":[{"mark":"26"}]},
    {
    "name": "John"
    },
    {
    "name": "John Doe",
    "code":"LP",
    "marks":[{"mark":"40"}]}
    ]
    }
2 of 4
0

I suggest you store the students in a table with a column for each attribute from the JSON. I am not familiar with Spring, but other web frameworks I used are able to fetch a row from the database and seralize it to JSON in the way you want. They can also take JSON and put it into the database as individual columns rather than an single string.

๐ŸŒ
Jsontostring
jsontostring.com โ€บ convert-json-to-one-line
Convert JSON to One Line | JSON Multiline to One Line Converter
Json one line converter is one of the most used online tools to ease any json multiline to one-line conversion. This tool provides great access over multiline, json to one line, convert json to one line, json to oneline, one line json without zero space.
๐ŸŒ
FreeFormatter
freeformatter.com โ€บ json-formatter.html
Free Online JSON Formatter - FreeFormatter.com
If you want to create a JSON string representation of your JavaScript object, make use of the JSON.stringify() function.
๐ŸŒ
W3 Percentage Calculator
w3percentagecalculator.com โ€บ json-to-one-line-converter
Json to One Line Converter | Json Multiline to Single Line Converter
Json Multiline to single line converter online tool - The best tool available online to convert multi-lines of JSON, json to one line, json to single line, json multiline to single line, multiline json to single line, json into a single line for free.
๐ŸŒ
Dadroit
dadroit.com โ€บ json-to-string
Quick JSON to String Conversion Tool
To convert JSON to String, visit the tool address, input your JSON data โ€”or load your JSON fileโ€” and the tool will display the corresponding String output in real time.
Find elsewhere
๐ŸŒ
Knowledgewalls
tools.knowledgewalls.com โ€บ online-multiline-to-single-line-converter
Online Multiline to Singleline Converter - Text/JSON/XML
Online tool to convert Multiline to Single Line, JSON to One Line and Text to One Line. Multiline Text, JSON, String or XML to Single Line by smart way.
๐ŸŒ
Code Beautify
codebeautify.org โ€บ json-to-one-line
JSON to One Line to convert json to single line
JSON to One Liner tool converts multiline JSON data to Single line, which save space and help developer to optimize json data.
๐ŸŒ
Online String Tools
onlinestringtools.com โ€บ convert-json-to-string
Convert JSON to a String โ€“ Online String Tools
Instant Copy-to-clipboardCopy the string to clipboard with a single click. ... This tool extracts all string values from a JavaScript Object Notation (JSON) file. It ignores all JSON notation characters and leaves just strings (and numbers, too.) Super simple! This tool extracts all string values from a JavaScript Object Notation (JSON) file. It ignores all JSON notation characters and leaves just strings (and numbers, too.) Super simple! Click to try! ... This example converts a nested JSON object to a plain string.
๐ŸŒ
JSON Formatter
jsonformatter.org โ€บ json-stringify-online
JSON Stringify Online using JSON.Stringify()
JSON Stringify Online helps convert string value to JSON String using JSON.Stringify().
๐ŸŒ
Online String Tools
onlinestringtools.com โ€บ json-stringify-string
JSON Stringify a String โ€“ Online String Tools
This example applies the stringify function to JS code. As a result, we get back the same code, except now it's a single-line JSON string.
๐ŸŒ
Code Beautify
codebeautify.org โ€บ json-to-string-online
JSON to String Converter to convert JSON data to JSON String.
Click on JSON to String button once data is available in Input Text Editor, via Paste, File, or URL ยท Download the converted string data or save and share.
๐ŸŒ
Online Tools
onlinetools.com โ€บ json โ€บ convert-json-to-text
Convert JSON to Plain Text โ€“ Online JSON Tools
Instant Copy-to-clipboardCopy the JSON to clipboard with a single click. ... This tool extracts plain text from JavaScript Object Notation (JSON) data structures and files. It removes all special JSON symbols, such as curly braces that are used to define objects, square brackets that are used to define arrays, quotes that wrap strings, colons that define key-value pairs, and commas that separate array items, leaving only clean text. Converting JSON to plain text allows you to get just the data inside of JSON.
๐ŸŒ
JSON Editor Online
jsoneditoronline.org
JSON Editor Online: edit JSON, format JSON, query JSON
JSON Editor Online is the original and most copied JSON Editor on the web. Use it to view, edit, format, repair, compare, query, transform, validate, and share your JSON data.
๐ŸŒ
ToolsHub
toolshub.dev โ€บ json-to-string
JSON to String Online - Fast Free Converter
Paste your JSON and click 'Convert' - instantly get a JavaScript-friendly string. No installation, no coding required. ... Generate strings exactly as JavaScript's JSON.stringify method would, making it ideal for API requests, data storage, and debugging. ... Turn your JSON into a compact, single-line string for embedding into code, saving space, or sending over the network.