Colton Idle
05/01/2023, 1:52 PM"
, it uses '
Is there an easy way to write an interceptor or something that just replace all double quotes with single quotes? I'm using okhttp + retrofit.Chris Lee
05/01/2023, 1:56 PMColton Idle
05/01/2023, 2:00 PMChris Lee
05/01/2023, 2:00 PMadvertised as taking json as inputYou already know this: that isn’t JSON. Specs: https://www.rfc-editor.org/rfc/rfc8259, https://www.json.org/json-en.html
A string begins and ends with
quotation marks.
…where quotation mark is 0x22 "
"
-> '
) when generating the json, or is that generation buried in the framework?Colton Idle
05/01/2023, 2:08 PM"Input is not valid json"
which is funny, because even the response isn't proper json because it doesn't have {} lolephemient
05/01/2023, 2:31 PMChris Lee
05/01/2023, 2:34 PMeygraber
05/01/2023, 2:35 PMyschimke
05/01/2023, 2:56 PMEarly versions of JSON (such as specified by RFC 4627) required that a valid JSON text must consist of only an object or an array type, which could contain other types within them. This restriction was dropped in RFC 7158, where a JSON text was redefined as any serialized value
Chris Lee
05/01/2023, 2:57 PM"
)yschimke
05/01/2023, 3:00 PMChris Lee
05/01/2023, 3:01 PMeygraber
05/01/2023, 3:17 PMChris Lee
05/01/2023, 3:18 PMColton Idle
05/01/2023, 3:20 PMephemient
05/01/2023, 3:21 PM"
-based JSON to '
-basedChris Lee
05/01/2023, 3:21 PMColton Idle
05/01/2023, 3:21 PMephemient
05/01/2023, 3:22 PMprivate enum class State {
Outside,
InsideString,
BeginEscape,
}
fun jsonHack(json: String): String = buildString(json.length) {
var state = State.Outside
for (c in json) {
when (state) {
State.Outside -> when (c) {
'"' -> {
append('\'')
state = State.InsideString
}
else -> append(c)
}
State.InsideString -> when (c) {
'"' -> {
append('\'')
state = State.Outside
}
'\\' -> {
append(c)
state = State.BeginEscape
}
'\'' -> append("\\'")
else -> append(c)
}
State.BeginEscape -> {
append(c)
state = State.InsideString
}
}
}
check(state == State.Outside)
}
Colton Idle
05/01/2023, 3:34 PMChris Lee
05/01/2023, 3:35 PMephemient
05/01/2023, 3:37 PMephemient
05/01/2023, 4:18 PMobject JsonHack : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
return chain.proceed(
request.newBuilder()
.method(
request.method,
request.body?.let { body ->
val buffer = Buffer()
body.writeTo(buffer)
buffer.readUtf8().jsonHack().toRequestBody(body.contentType())
}
)
.build()
)
}
}
using the previous functionyschimke
05/01/2023, 4:23 PMjessewilson
05/01/2023, 5:05 PMval lenientJsonAdapter = strictJsonAdapter.lenient()
Chris Lee
05/01/2023, 5:06 PMjessewilson
05/01/2023, 5:06 PM