So you have a lot of nesting here. You have JSON inside of NBT inside of a command inside of JSON inside of NBT inside of a command. Let's look at each component separately (outermost to innermost):
setblock -8 42 189 minecraft:birch_wall_sign[facing=east]{Text1:'…'}
{"text":"1","color":"black","clickEvent":{"action":"run_command","value":"…"}}
execute if entity @p[nbt={SelectedItem:{id:"minecraft:paper",tag:{display:{Name:'…'}}}}] run say hi
{"text":"1853914142"}
So we want to insert the contents of the fourth line into the spot marked …
on line 3, insert the result into line 2, and then line 1.
So to put line 4 into line 3, it's simple enough. We get this:
execute if entity @p[nbt={
SelectedItem: {
id: "minecraft:paper",
tag: {
display: {
Name: '{"text":"1853914142"}'
}
}
}
}] run say hi
Now to put that into line 2, we need to replace all instances of "
with \"
. If we had any \
s we'd replace them with \\
, but we don't… yet:
{
"text": "1",
"color": "black",
"clickEvent": {
"action": "run_command",
"value":"execute if entity @p[nbt={SelectedItem:{id:\"minecraft:paper\",tag:{display:{Name:'{\"text\":\"1853914142\"}'}}}}] run say hi"
}
}
And the big finish to put it all together into line 1. Because the string in line 1 is denoted with '
, we replace all '
s with \'
, and we replace all \
with \\
.
setblock -8 42 189 minecraft:birch_wall_sign[facing=east]{
Text1: '{"text":"1","color":"black","clickEvent":{"action":"run_command","value":"execute if entity @p[nbt={SelectedItem:{id:\\"minecraft:paper\\",tag:{display:{Name:\'{\\"text\\":\\"1853914142\\"}\'}}}}] run say hi"}}'
}
And that's our final answer.
Comparing it with what you originally had at the start:
setblock -8 42 189 minecraft:birch_wall_sign[facing=east]{
Text1: '{"text":"1","color":"black","clickEvent":{"action":"run_command","value":"execute if entity @p[nbt={SelectedItem:{id:"minecraft:paper",tag:{display:{Name:\'{"text":"1853914142"}\'}}}}] run say hi"}}'
}
Looks like you put just enough escaping so the NBT processor would validate the outer NBT, but the JSON inside of it was messed up, so the sign got confused and displayed nothing.