<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[JSON]]></title><description><![CDATA[<p dir="rtl">אני עובדת בימים אלו על כתיבת REST API עם פונקציונליות של CRUD<br />
יש לי בעיה שאני לא בטוחה מה הדרך הנכונה והנקיה לפתור אותה<br />
יש לי אובייקט עם הרבה שדות, שאני רוצה לאפשר עידכון רק לחלק מהשדות, בלי הצורך לשלוח JSON אם אובייקט שלם, אלא רק עם השדות שמעונינים לעדכן.<br />
בנוסף יש שדות שיכולים לקבל את הערך NULL<br />
כאן אני בבעיה איך אפשר להבדיל ערך שלא מופיע ב-JSON, שאני לא מעוניינת לעדכן, לבין ערך שאני רוצה לעדכן אותו ל-NULL<br />
כאשר ה-JSON מתורגם לאובייקט, ערך שלא מופיע ב-JSON גם כן מופיע כ-NULL</p>
<p dir="rtl">אודה לרעיונות!</p>
]]></description><link>https://tchumim.com/topic/5347/json</link><generator>RSS for Node</generator><lastBuildDate>Sun, 15 Nov 2026 18:37:29 GMT</lastBuildDate><atom:link href="https://tchumim.com/topic/5347.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 08 May 2019 07:35:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to JSON on Thu, 23 May 2019 12:49:51 GMT]]></title><description><![CDATA[<p dir="rtl">לא בטוח שזה קשור,<br />
אבל צריך לשים לב שיש null ויש Null<br />
Null זה מאפיין<br />
null זה ערך</p>
]]></description><link>https://tchumim.com/post/61635</link><guid isPermaLink="true">https://tchumim.com/post/61635</guid><dc:creator><![CDATA[upsilon01]]></dc:creator><pubDate>Thu, 23 May 2019 12:49:51 GMT</pubDate></item><item><title><![CDATA[Reply to JSON on Thu, 23 May 2019 10:27:06 GMT]]></title><description><![CDATA[<p dir="rtl">בפייתון השתמשתי בספריה שנקראת marshmallow שיש בה אפשרות ליצור scheme, שניתן להגדיר איתה בכל טופס שרוצים למלאות, איזה שדות למלאות, ואפשר להגדיר איזה KEY מהג'ייסון יתאים לאיזה שדה וכו', וניתן להגדיר לאותו טופס כמה סכמות ולקרוא כל פעם לסכמה הרצויה. ועוד אופציות רבות נוספות.<br />
בג'אוה לא יצא לי להשתמש במשהו דומה אבל אני בטוח שיש ספריה כזו שיותרת סכמות</p>
]]></description><link>https://tchumim.com/post/61618</link><guid isPermaLink="true">https://tchumim.com/post/61618</guid><dc:creator><![CDATA[מזדמן]]></dc:creator><pubDate>Thu, 23 May 2019 10:27:06 GMT</pubDate></item><item><title><![CDATA[Reply to JSON on Fri, 10 May 2019 07:23:35 GMT]]></title><description><![CDATA[<p dir="rtl">תודה רבה על התגובות! (היה יום הזיכרון ויום העצמאות..)</p>
<p dir="rtl">את ה-API, אני כותבת בשפת  scala, אבל נראה לי שהבעיה גם קיימת ב-java<br />
כאשר ה-json עובר deserialization לאובייקט, שני המצבים הבאים יקבלו ערך null:</p>
<ol>
<li>key ששלחנו לו ערך Null</li>
<li>key שלא שלחנו בכלל<br />
אני לא רוצה לוותר על האפשרות לעשות deserialization לאובייקט, בגלל שזה נותן לי בלי מאמץ וולידציות לסוגי הערכים שנשלחים.</li>
</ol>
<p dir="rtl">חשבתי אולי משהו בכיוון הזה - אבל לא בדקתי את זה עד הסוף: להשתמש deserialization לאובייקט רק בשביל הוולידציה, אבל אח"כ להמיר את זה לרשימה של key value list (זה אפשרי??), ולכתוב פונקציה שבונה sql update statement של כל הערכים ברשימה.</p>
<ol>
<li>אני לא יודעת אם אפשרי להמיר json ל-key value list</li>
<li>איך אדע איזה מהם עמודת ה-ID בשביל ה-where statement</li>
</ol>
<p dir="rtl">עוד פיתרון שחשבתי, אבל הר"צ לא כ"כ אהב<br />
ערך שאני רוצה לעדכן כ-null, אשלח אותו כמחרוזת "null" וארשום טיפול מיוחד במחרוזת הזאת</p>
]]></description><link>https://tchumim.com/post/60188</link><guid isPermaLink="true">https://tchumim.com/post/60188</guid><dc:creator><![CDATA[ps]]></dc:creator><pubDate>Fri, 10 May 2019 07:23:35 GMT</pubDate></item><item><title><![CDATA[Reply to JSON on Thu, 09 May 2019 14:26:42 GMT]]></title><description><![CDATA[<p dir="rtl"><a class="plugin-mentions-user plugin-mentions-a" href="/user/%D7%9E%D7%A2%D7%9E%D7%93" aria-label="Profile: מעמד">@<bdi>מעמד</bdi></a><br />
אוקיי<br />
חוזר בי <img src="https://tchumim.com/assets/plugins/nodebb-plugin-emoji/emoji/android/1f62e.png?v=cf1b4e11576" class="not-responsive emoji emoji-android emoji--open_mouth" style="height:23px;width:auto;vertical-align:middle" title=":O" alt="😮" /><br />
תודה על ההארה</p>
]]></description><link>https://tchumim.com/post/60101</link><guid isPermaLink="true">https://tchumim.com/post/60101</guid><dc:creator><![CDATA[clickone]]></dc:creator><pubDate>Thu, 09 May 2019 14:26:42 GMT</pubDate></item><item><title><![CDATA[Reply to JSON on Wed, 08 May 2019 17:07:30 GMT]]></title><description><![CDATA[<p dir="rtl"><a class="plugin-mentions-user plugin-mentions-a" href="/user/%D7%97%D7%95%D7%A7%D7%A8" aria-label="Profile: חוקר">@<bdi>חוקר</bdi></a> את זה <a class="plugin-mentions-user plugin-mentions-a" href="/user/clickone" aria-label="Profile: clickone">@<bdi>clickone</bdi></a> צריך לראות</p>
]]></description><link>https://tchumim.com/post/59973</link><guid isPermaLink="true">https://tchumim.com/post/59973</guid><dc:creator><![CDATA[מעמד]]></dc:creator><pubDate>Wed, 08 May 2019 17:07:30 GMT</pubDate></item><item><title><![CDATA[Reply to JSON on Wed, 08 May 2019 17:05:44 GMT]]></title><description><![CDATA[<p dir="rtl"><a class="plugin-mentions-user plugin-mentions-a" href="/user/%D7%9E%D7%A2%D7%9E%D7%93" aria-label="Profile: מעמד">@<bdi>מעמד</bdi></a> אמר ב<a href="/post/59937">JSON</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/clickone" aria-label="Profile: clickone">@<bdi>clickone</bdi></a> לא מסכים איתך<br />
גם אם התשובה תגיע אחרי חצי שעה, לא קרה כלום שהיא לא רואה. ההודעות פה לא נמחקות<br />
אז מחר היא תבוא ותראה !<br />
מאד יכול להיות שאדם שואל שאלה והוא בונה על זה שיכול להיות שמי שיש לו את הידע, לא נמצא כעת בפורום, אבל יענה לה בהמשך<br />
מאד יכול ליות שהיא לא יכולה לחכות כי היא עסוקה</p>
</blockquote>
<p dir="rtl">לי קורה שי לי שאלות אפילו דחופות, אבל יש משימות עוד יותר דחופות, כך שנוצר מצב ששאלתי שאלה ורק אחרי יומיים (או יותר)  חזרתי לראות את התשובות</p>
]]></description><link>https://tchumim.com/post/59970</link><guid isPermaLink="true">https://tchumim.com/post/59970</guid><dc:creator><![CDATA[חוקר]]></dc:creator><pubDate>Wed, 08 May 2019 17:05:44 GMT</pubDate></item><item><title><![CDATA[Reply to JSON on Wed, 08 May 2019 13:29:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/clickone" aria-label="Profile: clickone">@<bdi>clickone</bdi></a> לא מסכים איתך<br />
גם אם התשובה תגיע אחרי חצי שעה, לא קרה כלום שהיא לא רואה. ההודעות פה לא נמחקות<br />
אז מחר היא תבוא ותראה !<br />
מאד יכול להיות שאדם שואל שאלה והוא בונה על זה שיכול להיות שמי שיש לו את הידע, לא נמצא כעת בפורום, אבל יענה לה בהמשך<br />
מאד יכול ליות שהיא לא יכולה לחכות כי היא עסוקה</p>
]]></description><link>https://tchumim.com/post/59937</link><guid isPermaLink="true">https://tchumim.com/post/59937</guid><dc:creator><![CDATA[מעמד]]></dc:creator><pubDate>Wed, 08 May 2019 13:29:16 GMT</pubDate></item><item><title><![CDATA[Reply to JSON on Thu, 09 May 2019 14:26:09 GMT]]></title><description><![CDATA[<p dir="rtl"><a class="plugin-mentions-user plugin-mentions-a" href="/user/%D7%9E%D7%A2%D7%9E%D7%93" aria-label="Profile: מעמד">@<bdi>מעמד</bdi></a><br />
2. זה לא הייתה שאלה של משהו מיידי / דחוף, אלא שאלה כללית איך לתכנן. בהחלט גם אם יענו על זה רק לאחר יום זה יהיה רלבנטי בשבילה.</p>
<p dir="rtl">בכל מקרה אני דן לכף זכות שכנראה שהיא הייתה עסוקה, או מצאה פיתרון כבר לפני שענו לה.</p>
]]></description><link>https://tchumim.com/post/59936</link><guid isPermaLink="true">https://tchumim.com/post/59936</guid><dc:creator><![CDATA[clickone]]></dc:creator><pubDate>Thu, 09 May 2019 14:26:09 GMT</pubDate></item><item><title><![CDATA[Reply to JSON on Wed, 08 May 2019 12:53:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/clickone" aria-label="Profile: clickone">@<bdi>clickone</bdi></a> מסתבר שהיא לא יכולה לחכות על המחשב כיון שאין דרך לדעת מתי יענו אם מיד כשמעלים את השאלה או 5 שעות אחרי או שעה אחרי<br />
לפעמים יש שאלות שעונים עליהם מיד, ולפעמים עונים רק לאחר זמן<br />
אתה רוצה היא תחכה עד שמישהו יענה ?</p>
]]></description><link>https://tchumim.com/post/59933</link><guid isPermaLink="true">https://tchumim.com/post/59933</guid><dc:creator><![CDATA[מעמד]]></dc:creator><pubDate>Wed, 08 May 2019 12:53:55 GMT</pubDate></item><item><title><![CDATA[Reply to JSON on Wed, 08 May 2019 11:53:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yossiz" aria-label="Profile: yossiz">@<bdi>yossiz</bdi></a><br />
רוב השאלות שלה זה בC#. לכן הנחתי שזו השפה.</p>
<p dir="rtl">חבל רק שהיא שאלה את השאלה, ולא באה לבדוק אם מישהו הגיב.... <img src="https://tchumim.com/assets/plugins/nodebb-plugin-emoji/emoji/android/1f61e.png?v=cf1b4e11576" class="not-responsive emoji emoji-android emoji--disappointed" style="height:23px;width:auto;vertical-align:middle" title=":(" alt="😞" /></p>
]]></description><link>https://tchumim.com/post/59924</link><guid isPermaLink="true">https://tchumim.com/post/59924</guid><dc:creator><![CDATA[clickone]]></dc:creator><pubDate>Wed, 08 May 2019 11:53:13 GMT</pubDate></item><item><title><![CDATA[Reply to JSON on Wed, 08 May 2019 11:30:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/clickone" aria-label="Profile: clickone">@<bdi>clickone</bdi></a> אהה, לא שמתי לב שאתה בכלל ב-#C... ואני דיברתי JS.<br />
חכם עדיף מנביא,<br />
למה לא לכתוב ברור בשאלה על איזה שפה מדובר ( <a class="plugin-mentions-user plugin-mentions-a" href="/user/ps" aria-label="Profile: ps">@<bdi>ps</bdi></a> )?</p>
]]></description><link>https://tchumim.com/post/59922</link><guid isPermaLink="true">https://tchumim.com/post/59922</guid><dc:creator><![CDATA[yossiz]]></dc:creator><pubDate>Wed, 08 May 2019 11:30:40 GMT</pubDate></item><item><title><![CDATA[Reply to JSON on Wed, 08 May 2019 11:21:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yossiz" aria-label="Profile: yossiz">@<bdi>yossiz</bdi></a><br />
היא עושה SerializeObject לאובייקט ממשי, ולא לאובייקט וירטואלי שיכול לקבל כל ערך.<br />
אלא יש שם כבר פרופרטיז, והSerializeObject ממיר את זה אוטומטית.</p>
<p dir="rtl">ואני רציתי ללכת בכיוון שאם השדה לא נמצא אז שלא ייכנס, או שיהיה שם ערך קבוע (לדוגמא אם זה שדה מספרי שהערך הולידי שלו הוא מעל אפס, שיהיה שם -1 ואז לבדוק אם זה שווה -1 ואז להמשיך וכו)</p>
<p dir="rtl">אבל לכאורה אפשר לזרום גם עם הרעיון שלך</p>
<pre><code>public static bool HasProperty(this object obj, string propertyName)
{
    return obj.GetType().GetProperty(propertyName) != null;
}

</code></pre>
<p dir="rtl">מול אובייקט לא מוגדר<br />
ואז פשוט לבדוק אם הפרופרטי קיים שם.</p>
<p dir="rtl">מקור לכיוון<br />
<a href="https://stackoverflow.com/questions/15341028/check-if-a-property-exist-in-a-class" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/questions/15341028/check-if-a-property-exist-in-a-class</a></p>
]]></description><link>https://tchumim.com/post/59918</link><guid isPermaLink="true">https://tchumim.com/post/59918</guid><dc:creator><![CDATA[clickone]]></dc:creator><pubDate>Wed, 08 May 2019 11:21:21 GMT</pubDate></item><item><title><![CDATA[Reply to JSON on Wed, 08 May 2019 11:03:47 GMT]]></title><description><![CDATA[<p dir="rtl">למעשה, כנראה שלא הבנתי את השאלה, כי שדה שלא קיים מחזיר <code>undefined</code> לעומת שדה עם ערך של <code>null</code> שמחזיר <code>null</code></p>
]]></description><link>https://tchumim.com/post/59908</link><guid isPermaLink="true">https://tchumim.com/post/59908</guid><dc:creator><![CDATA[yossiz]]></dc:creator><pubDate>Wed, 08 May 2019 11:03:47 GMT</pubDate></item><item><title><![CDATA[Reply to JSON on Wed, 08 May 2019 11:00:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/clickone" aria-label="Profile: clickone">@<bdi>clickone</bdi></a> או שלא הבנתי נכון את השאלה או שלא הבנתי את הפתרון שלך,</p>
<p dir="rtl">אני הבנתי את השאלה כך: מקבלים אובייקט JSON מהקליינט עם שדות לעדכון, איך מבחינים בקוד צד שרת בין שדה שדה שקיים עם ערך של <code>null</code> לבין שדה שלא קיים באובייקט.<br />
אם בודקים כך:</p>
<pre><code>var obj = JSON.parse(jsonMessage);
if (obj.property_a) db.update(obj.property_a);
...
</code></pre>
<p dir="rtl">אז מפספסים מקרה שהלקוח ביקש עדכון של <code>property_a</code> ל-<code>null</code><br />
ואם הבנתי נכון את השאלה, אז התשובה לכאורה פשוטה:</p>
<pre><code>if obj.hasOwnProperty('property_a')  db.update(obj.property_a);
</code></pre>
]]></description><link>https://tchumim.com/post/59901</link><guid isPermaLink="true">https://tchumim.com/post/59901</guid><dc:creator><![CDATA[yossiz]]></dc:creator><pubDate>Wed, 08 May 2019 11:00:37 GMT</pubDate></item><item><title><![CDATA[Reply to JSON on Wed, 08 May 2019 08:04:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ps" aria-label="Profile: ps">@<bdi>ps</bdi></a><br />
לדעתי אפשר להשתמש בפורמט<br />
בתור התחלה, ראו כאן<br />
<a href="https://www.newtonsoft.com/json/help/html/NullValueHandlingIgnore.htm" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.newtonsoft.com/json/help/html/NullValueHandlingIgnore.htm</a></p>
<pre><code>Person person = new Person
{
    Name = "Nigal Newborn",
    Age = 1
};

string jsonIncludeNullValues = JsonConvert.SerializeObject(person, Formatting.Indented);

Console.WriteLine(jsonIncludeNullValues);
// {
//   "Name": "Nigal Newborn",
//   "Age": 1,
//   "Partner": null,
//   "Salary": null
// }

string jsonIgnoreNullValues = JsonConvert.SerializeObject(person, Formatting.Indented, new JsonSerializerSettings
{
    NullValueHandling = NullValueHandling.Ignore
});

Console.WriteLine(jsonIgnoreNullValues);
// {
//   "Name": "Nigal Newborn",
//   "Age": 1
// }

</code></pre>
]]></description><link>https://tchumim.com/post/59885</link><guid isPermaLink="true">https://tchumim.com/post/59885</guid><dc:creator><![CDATA[clickone]]></dc:creator><pubDate>Wed, 08 May 2019 08:04:23 GMT</pubDate></item></channel></rss>