All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.jupyter.parser.JupyterParser.kt Maven / Gradle / Ivy

There is a newer version: 0.2.0-dev-10
Show newest version
package org.jetbrains.jupyter.parser

import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.jetbrains.jupyter.parser.notebook.JupyterNotebook
import java.io.File

public object JupyterParser {
    private val parser = Json {
        ignoreUnknownKeys = true
        prettyPrint = true
    }

    public fun parse(text: String): JupyterNotebook {
        return parser.decodeFromString(text)
    }

    public fun parse(file: File): JupyterNotebook {
        return parse(file.readText())
    }

    public fun saveToJson(notebook: JupyterNotebook): String {
        return parser.encodeToString(notebook)
    }

    public fun save(notebook: JupyterNotebook, file: File) {
        file.writeText(saveToJson(notebook))
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy