# Can not save a json string

**URL:** <https://www.ruby-forum.com/t/can-not-save-a-json-string/177764>\
**Category:** Rails\
**Created:** [October 23, 2009, 9:11am UTC](https://www.ruby-forum.com/t/can-not-save-a-json-string/177764 "2009-10-23T09:11:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [October 23, 2009, 9:11am UTC](https://www.ruby-forum.com/t/can-not-save-a-json-string/177764/1 "2009-10-23T09:11:37Z")

</div>

I have a json string like below

‘{“id”:null,“name”:null,“count”:26,“nodes”:[{“id”:“node\_1”,“name”:“node\_1”,“type”:“start”,“shape”:“oval”,“number”:1,“left”:100,“top”:80,“width”:20,“height”:20,“property”:null},{“id”:“node\_2”,“name”:“node\_2”,“type”:“end”,“shape”:“oval”,“number”:2,“left”:753,“top”:462,“width”:20,“height”:20,“property”:null},{“id”:“node\_3”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:3,“left”:195,“top”:69,“width”:100,“height”:40,“property”:{“role”:1,“description”:“test”}},{“id”:“node\_4”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:4,“left”:196,“top”:141,“width”:100,“height”:40,“property”:{“role”:2,“description”:“test”}},{“id”:“node\_5”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:5,“left”:197,“top”:210,“width”:100,“height”:40,“property”:{“role”:3,“description”:“test”}},{“id”:“node\_6”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:6,“left”:197,“top”:280,“width”:100,“height”:40,“property”:{“role”:4,“description”:“test”}},{“id”:“node\_11”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:11,“left”:260,“top”:453,“width”:100,“height”:40,“property”:{“role”:9,“description”:“test”}},{“id”:“node\_14”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:14,“left”:427,“top”:67,“width”:100,“height”:40,“property”:{“role”:5,“description”:“test”}},{“id”:“node\_15”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:15,“left”:427,“top”:139,“width”:100,“height”:40,“property”:{“role”:6,“description”:“test”}},{“id”:“node\_19”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:19,“left”:426,“top”:216,“width”:100,“height”:40,“property”:{“role”:7,“description”:“test”}},{“id”:“node\_20”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:20,“left”:429,“top”:308,“width”:100,“height”:40,“property”:{“role”:8,“description”:“test”}},{“id”:“node\_24”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:24,“left”:489,“top”:449,“width”:100,“height”:40,“property”:{“role”:10,“description”:“test”}}],“lines”:[{“id”:“line\_7”,“name”:“line\_7”,“type”:“line”,“shape”:“line”,“number”:7,“from”:“node\_1”,“to”:“node\_3”,“fromx”:120,“fromy”:90,“tox”:195,“toy”:89,“polydot”:[],“property”:null},{“id”:“line\_8”,“name”:“line\_8”,“type”:“line”,“shape”:“line”,“number”:8,“from”:“node\_3”,“to”:“node\_4”,“fromx”:245,“fromy”:109,“tox”:246,“toy”:141,“polydot”:[],“property”:null},{“id”:“line\_9”,“name”:“line\_9”,“type”:“line”,“shape”:“line”,“number”:9,“from”:“node\_4”,“to”:“node\_5”,“fromx”:246,“fromy”:181,“tox”:247,“toy”:210,“polydot”:[],“property”:null},{“id”:“line\_10”,“name”:“line\_10”,“type”:“line”,“shape”:“line”,“number”:10,“from”:“node\_5”,“to”:“node\_6”,“fromx”:247,“fromy”:250,“tox”:247,“toy”:280,“polydot”:[],“property”:null},{“id”:“line\_12”,“name”:“line\_12”,“type”:“line”,“shape”:“line”,“number”:12,“from”:“node\_6”,“to”:“node\_11”,“fromx”:247,“fromy”:320,“tox”:260,“toy”:453,“polydot”:[],“property”:null},{“id”:“line\_16”,“name”:“line\_16”,“type”:“line”,“shape”:“line”,“number”:16,“from”:“node\_6”,“to”:“node\_14”,“fromx”:297,“fromy”:280,“tox”:427,“toy”:107,“polydot”:[],“property”:null},{“id”:“line\_17”,“name”:“line\_17”,“type”:“line”,“shape”:“line”,“number”:17,“from”:“node\_14”,“to”:“node\_15”,“fromx”:477,“fromy”:107,“tox”:477,“toy”:139,“polydot”:[],“property”:null},{“id”:“line\_18”,“name”:“line\_18”,“type”:“line”,“shape”:“line”,“number”:18,“from”:“node\_15”,“to”:“node\_11”,“fromx”:427,“fromy”:179,“tox”:360,“toy”:453,“polydot”:[],“property”:null},{“id”:“line\_21”,“name”:“line\_21”,“type”:“line”,“shape”:“line”,“number”:21,“from”:“node\_15”,“to”:“node\_19”,“fromx”:477,“fromy”:179,“tox”:476,“toy”:216,“polydot”:[],“property”:null},{“id”:“line\_22”,“name”:“line\_22”,“type”:“line”,“shape”:“line”,“number”:22,“from”:“node\_19”,“to”:“node\_20”,“fromx”:476,“fromy”:256,“tox”:479,“toy”:308,“polydot”:[],“property”:null},{“id”:“line\_23”,“name”:“line\_23”,“type”:“line”,“shape”:“line”,“number”:23,“from”:“node\_20”,“to”:“node\_11”,“fromx”:429,“fromy”:348,“tox”:360,“toy”:453,“polydot”:[],“property”:null},{“id”:“line\_25”,“name”:“line\_25”,“type”:“line”,“shape”:“line”,“number”:25,“from”:“node\_11”,“to”:“node\_24”,“fromx”:360,“fromy”:473,“tox”:489,“toy”:469,“polydot”:[],“property”:null},{“id”:“line\_26”,“name”:“line\_26”,“type”:“line”,“shape”:“line”,“number”:26,“from”:“node\_24”,“to”:“node\_2”,“fromx”:589,“fromy”:469,“tox”:753,“toy”:472,“polydot”:[],“property”:null}]}’

I save it in a text field, when I read it from databace, it become  
unreadable code.

I test it by the code below:

f=Flow.find(1)  
f=‘json string above’  
f.save!  
p f.jsonstring

it’s right,but if I read it again from database, it become unreadable  
code.  
f=Flow.find(1)  
f=‘json string above’  
f.save!  
f=Flow.find(1)  
p f.jsonstring

Anyone can help me?

---

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [October 23, 2009, 9:19am UTC](https://www.ruby-forum.com/t/can-not-save-a-json-string/177764/2 "2009-10-23T09:19:29Z")

</div>

Michael G. wrote:

> I have a json string like below
> 
> ‘{“id”:null,“name”:null,“count”:26,“nodes”:[{“id”:“node\_1”,“name”:“node\_1”,“type”:“start”,“shape”:“oval”,“number”:1,“left”:100,“top”:80,“width”:20,“height”:20,“property”:null},{“id”:“node\_2”,“name”:“node\_2”,“type”:“end”,“shape”:“oval”,“number”:2,“left”:753,“top”:462,“width”:20,“height”:20,“property”:null},{“id”:“node\_3”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:3,“left”:195,“top”:69,“width”:100,“height”:40,“property”:{“role”:1,“description”:“test”}},{“id”:“node\_4”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:4,“left”:196,“top”:141,“width”:100,“height”:40,“property”:{“role”:2,“description”:“test”}},{“id”:“node\_5”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:5,“left”:197,“top”:210,“width”:100,“height”:40,“property”:{“role”:3,“description”:“test”}},{“id”:“node\_6”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:6,“left”:197,“top”:280,“width”:100,“height”:40,“property”:{“role”:4,“description”:“test”}},{“id”:“node\_11”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:11,“left”:260,“top”:453,“width”:100,“height”:40,“property”:{“role”:9,“description”:“test”}},{“id”:“node\_14”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:14,“left”:427,“top”:67,“width”:100,“height”:40,“property”:{“role”:5,“description”:“test”}},{“id”:“node\_15”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:15,“left”:427,“top”:139,“width”:100,“height”:40,“property”:{“role”:6,“description”:“test”}},{“id”:“node\_19”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:19,“left”:426,“top”:216,“width”:100,“height”:40,“property”:{“role”:7,“description”:“test”}},{“id”:“node\_20”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:20,“left”:429,“top”:308,“width”:100,“height”:40,“property”:{“role”:8,“description”:“test”}},{“id”:“node\_24”,“name”:“test”,“type”:“node”,“shape”:“rect”,“number”:24,“left”:489,“top”:449,“width”:100,“height”:40,“property”:{“role”:10,“description”:“test”}}],“lines”:[{“id”:“line\_7”,“name”:“line\_7”,“type”:“line”,“shape”:“line”,“number”:7,“from”:“node\_1”,“to”:“node\_3”,“fromx”:120,“fromy”:90,“tox”:195,“toy”:89,“polydot”:[],“property”:null},{“id”:“line\_8”,“name”:“line\_8”,“type”:“line”,“shape”:“line”,“number”:8,“from”:“node\_3”,“to”:“node\_4”,“fromx”:245,“fromy”:109,“tox”:246,“toy”:141,“polydot”:[],“property”:null},{“id”:“line\_9”,“name”:“line\_9”,“type”:“line”,“shape”:“line”,“number”:9,“from”:“node\_4”,“to”:“node\_5”,“fromx”:246,“fromy”:181,“tox”:247,“toy”:210,“polydot”:[],“property”:null},{“id”:“line\_10”,“name”:“line\_10”,“type”:“line”,“shape”:“line”,“number”:10,“from”:“node\_5”,“to”:“node\_6”,“fromx”:247,“fromy”:250,“tox”:247,“toy”:280,“polydot”:[],“property”:null},{“id”:“line\_12”,“name”:“line\_12”,“type”:“line”,“shape”:“line”,“number”:12,“from”:“node\_6”,“to”:“node\_11”,“fromx”:247,“fromy”:320,“tox”:260,“toy”:453,“polydot”:[],“property”:null},{“id”:“line\_16”,“name”:“line\_16”,“type”:“line”,“shape”:“line”,“number”:16,“from”:“node\_6”,“to”:“node\_14”,“fromx”:297,“fromy”:280,“tox”:427,“toy”:107,“polydot”:[],“property”:null},{“id”:“line\_17”,“name”:“line\_17”,“type”:“line”,“shape”:“line”,“number”:17,“from”:“node\_14”,“to”:“node\_15”,“fromx”:477,“fromy”:107,“tox”:477,“toy”:139,“polydot”:[],“property”:null},{“id”:“line\_18”,“name”:“line\_18”,“type”:“line”,“shape”:“line”,“number”:18,“from”:“node\_15”,“to”:“node\_11”,“fromx”:427,“fromy”:179,“tox”:360,“toy”:453,“polydot”:[],“property”:null},{“id”:“line\_21”,“name”:“line\_21”,“type”:“line”,“shape”:“line”,“number”:21,“from”:“node\_15”,“to”:“node\_19”,“fromx”:477,“fromy”:179,“tox”:476,“toy”:216,“polydot”:[],“property”:null},{“id”:“line\_22”,“name”:“line\_22”,“type”:“line”,“shape”:“line”,“number”:22,“from”:“node\_19”,“to”:“node\_20”,“fromx”:476,“fromy”:256,“tox”:479,“toy”:308,“polydot”:[],“property”:null},{“id”:“line\_23”,“name”:“line\_23”,“type”:“line”,“shape”:“line”,“number”:23,“from”:“node\_20”,“to”:“node\_11”,“fromx”:429,“fromy”:348,“tox”:360,“toy”:453,“polydot”:[],“property”:null},{“id”:“line\_25”,“name”:“line\_25”,“type”:“line”,“shape”:“line”,“number”:25,“from”:“node\_11”,“to”:“node\_24”,“fromx”:360,“fromy”:473,“tox”:489,“toy”:469,“polydot”:[],“property”:null},{“id”:“line\_26”,“name”:“line\_26”,“type”:“line”,“shape”:“line”,“number”:26,“from”:“node\_24”,“to”:“node\_2”,“fromx”:589,“fromy”:469,“tox”:753,“toy”:472,“polydot”:[],“property”:null}]}’
> 
> I save it in a text field, when I read it from databace, it become  
> unreadable code.
> 
> I test it by the code below:
> 
> f=Flow.find(1)  
> f=‘json string above’  
> f.save!  
> p f.jsonstring
> 
> it’s right,but if I read it again from database, it become unreadable  
> code.  
> f=Flow.find(1)  
> f=‘json string above’  
> f.save!  
> f=Flow.find(1)  
> p f.jsonstring
> 
> Anyone can help me?

Ok, I got it. In the database, the field type is varchar[MAX], I change  
the field type to text, it work.  
Here is another question. I user the ror+sqlserver, and I create the  
field use :text key. Why it will become varchar[MAX], or which key can I  
use next if I want to create text field
