Scala circe json
Guide for using Circe in Scala 2.13 for parsing and generating JSON, specifically when translating Python JSON handling.From its SKILL.md
npx -y skills add cxcscmu/SkillLearnBench --skill scala-circe-jsonAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
1.4 KB, 344 tokens by cl100k_base, as published. Nobody here has run it
Using Circe for JSON in Scala 2.13
When converting Python's json module usage (e.g., json.loads, json.dumps, JsonValue = Union[...]), Scala relies on the Circe library. Since Scala 2.13 does not support native union types, JSON trees are best represented using the io.circe.Json Algebraic Data Type (ADT).
Setup
Ensure Circe dependencies are available.
import io.circe._
import io.circe.parser._
import io.circe.syntax._
Basic Operations
Parsing JSON (like json.loads)
In Python:
import json
data = json.loads('{"key":"value"}')
In Scala:
val jsonString = """{"key":"value"}"""
val jsonAst = parse(jsonString).getOrElse(Json.Null)
Serializing JSON (like json.dumps)
In Python:
json.dumps(data)
json.dumps(data, indent=2)
In Scala:
val compactStr = jsonAst.noSpaces
val prettyStr = jsonAst.spaces2
Navigating JSON Trees
Python uses dict/list indexing:
value = data.get("key")[0]
In Scala, use Cursors or pattern matching on Json methods:
val valueOption = jsonAst.hcursor.downField("key").downArray.focus
// or traversing Json values directly:
val objOption: Option[JsonObject] = jsonAst.asObject
val arrOption: Option[Vector[Json]] = jsonAst.asArray
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.